dropdown list won't polpuate values from database
<p>I'm stuck with a problem to populate a DropDownList control with values from the database  using item field template in read only mode. I appreciate a detailed explanation, since I'm new to ASP.NET. Below is the code and the error I'm getting:</p>

<blockquote>
  <p>'PictureReadOnlyCategories' has a SelectedValue which is invalid because it does not exist in the list of items.
  Parameter name: value Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>
  
  <p>Exception Details: System.ArgumentOutOfRangeException: 'PictureReadOnlyCategories' has a SelectedValue which is invalid because it does not exist in the list of items.
  Parameter name: value</p>
</blockquote>

<p>The code for this is :</p>

<pre><code>&lt;asp:SqlDataSource ID="categoriesDataSource" runat="server" 
    ConnectionString="&lt;%$ ConnectionStrings:ConnectionString %&gt;" 
    SelectCommand ="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId)"&gt;
    &lt;SelectParameters&gt;
        &lt;asp:ControlParameter ControlID="UserIdValue" 
                              Name="UserId"
                              PropertyName="Text" /&gt;
    &lt;/SelectParameters&gt;
&lt;/asp:SqlDataSource&gt;

&lt;asp:Label ID="UserIdValue" runat="server" Visible="False"&gt;&lt;/asp:Label&gt;

&lt;asp:GridView ID="gvPictures"
              runat="server"
              AllowPaging="True" 
              AllowSorting="True"
              AutoGenerateColumns="False"
              CellPadding="4"
              DataKeyNames="PictureID"
              DataSourceID="picturesDataSource"
              ForeColor="#333333"
              GridLines="None" Width="800px"&gt; 
    &lt;AlternatingRowStyle BackColor="White" /&gt; 
    &lt;Columns&gt; 
        &lt;asp:CommandField ShowDeleteButton="True"
                          ShowEditButton="True"
                          ValidationGroup="PictureEdit" /&gt; 
         &lt;asp:TemplateField HeaderText="Category"
                            SortExpression="CategoryID"&gt; 
             &lt;EditItemTemplate&gt; 
                 &lt;asp:DropDownList ID="pictureEditCategories"
                                   runat="server"
                                   AppendDataBoundItems="True"
                                   DataSourceID="categoriesDataSource"
                                   DataTextField="Name"
                                   DataValueField="CategoryID"
                                   SelectedValue='&lt;%# Bind("CategoryID") %&gt;'&gt; 
                     &lt;asp:ListItem Value="" Text="--Select Category -- "/&gt; 
                 &lt;/asp:DropDownList&gt; 
             &lt;/EditItemTemplate&gt; 
             &lt;ItemTemplate&gt;
                 &lt;asp:DropDownList ID="PictureReadOnlyCategories"
                                   runat="server"
                                   AppendDataBoundItems="True"
                                   DataSourceID="categoriesDataSource" 
                                   DataTextField="Name"
                                   DataValueField="CategoryID"
                                   Enabled="False"
                                   SelectedValue='&lt;%# Bind("CategoryID") %&gt;'&gt;
                     &lt;asp:ListItem Selected="True" Value=""&gt;-- No Category --&lt;/asp:ListItem&gt; 
                &lt;/asp:DropDownList&gt;
            &lt;/ItemTemplate&gt; 
         &lt;/asp:TemplateField&gt;
         &lt;asp:TemplateField HeaderText="Title" SortExpression="Title"&gt; 
            &lt;EditItemTemplate&gt;
                &lt;asp:TextBox ID="TextBox1"
                             runat="server"
                             EnableViewState="False"
                             Text='&lt;%# Bind("Title") %&gt;'&gt;
                &lt;/asp:TextBox&gt; 
                &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator4"
                                            runat="server"
                                            ControlToValidate="TextBox1"
                                            Display="Dynamic"
                                            ErrorMessage="must enter a title"
                                            ValidationGroup="PictureEdit"&gt;
                &lt;/asp:RequiredFieldValidator&gt;
            &lt;/EditItemTemplate&gt; 
            &lt;ItemTemplate&gt; 
                &lt;asp:Label ID="Label1"
                           runat="server"
                           Text='&lt;%# Bind("Title") %&gt;'&gt;
                &lt;/asp:Label&gt; 
            &lt;/ItemTemplate&gt; 
        &lt;/asp:TemplateField&gt; 
        &lt;asp:TemplateField HeaderText="Description" SortExpression="Description"&gt; 
            &lt;EditItemTemplate&gt; 
                &lt;asp:TextBox ID="TextBox2"
                             runat="server"
                             Columns="25"
                             Rows="4"
                             Text='&lt;%# Bind("Description") %&gt;'
                             TextMode="MultiLine"&gt;
                &lt;/asp:TextBox&gt; 
                &lt;asp:RequiredFieldValidator ID="RequiredFieldValidator5"
                                            runat="server"
                                            ControlToValidate="TextBox2"
                                            Display="Dynamic"
                                            ErrorMessage="you must enter a description"
                                            ValidationGroup="PictureEdit"&gt;
                &lt;/asp:RequiredFieldValidator&gt;&lt;
            &lt;/EditItemTemplate&gt; 
            &lt;ItemTemplate&gt;
                &lt;asp:Label ID="Label2"
                           runat="server"
                           Text='&lt;%# Bind("Description") %&gt;'&gt;
                &lt;/asp:Label&gt;
            &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt;
        &lt;asp:TemplateField HeaderText="Date Added" SortExpression="UploadedOn"&gt; 
            &lt;EditItemTemplate&gt;
                &lt;asp:Label ID="Label4"
                           runat="server"
                           Text='&lt;%# Bind("UploadedOn") %&gt;'&gt;
                &lt;/asp:Label&gt;
            &lt;/EditItemTemplate&gt; 
            &lt;ItemTemplate&gt; 
                &lt;asp:Label ID="Label3"
                           runat="server"
                           Text='&lt;%# Bind("UploadedOn") %&gt;'&gt;
                &lt;/asp:Label&gt;
            &lt;/ItemTemplate&gt;
        &lt;/asp:TemplateField&gt; 
        &lt;asp:ImageField DataImageUrlField="PictureID"
                        DataImageUrlFormatString="~/UploadedImages/{0}.jpg"
                        HeaderText="Image"
                        ReadOnly="True"&gt; 
            &lt;ControlStyle Width="100px" /&gt; 
        &lt;/asp:ImageField&gt;
    &lt;/Columns&gt; 
    &lt;EditRowStyle BackColor="#2461BF" /&gt; 
    &lt;FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt; 
    &lt;HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /&gt; 
    &lt;PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /&gt; 
    &lt;RowStyle BackColor="#EFF3FB" /&gt;
    &lt;SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /&gt; 
    &lt;SortedAscendingCellStyle BackColor="#F5F7FB" /&gt; 
    &lt;SortedAscendingHeaderStyle BackColor="#6D95E1" /&gt; 
    &lt;SortedDescendingCellStyle BackColor="#E9EBEF" /&gt; 
    &lt;SortedDescendingHeaderStyle BackColor="#4870BE" /&gt; 
 &lt;/asp:GridView&gt;
</code></pre>
