dropdown list in edit and read-only mode
<p>Hello i have a dropdown list in edit mode and read only mode. If users upload pictures, i want them to chose a category for the uploaded pics and display it in a gridview as below.(See Picture below).
When i include "SelectedValue='&lt;%# Bind("CategoryID")" in edit and item template mode, i get this error "'PictureReadOnlyCategories' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value "</p>

<p>When i removed the "SelectedValue='&lt;%# Bind("CategoryID")" from edit and item template, i get the result on the pic below(screenshot). If u can see the pic below the category is not selected, it just display the -- No Category -- even when i chose a category for the pic.</p>

<p>I want when a pic is uploaded and i category chosen, to display on the gridview. The code for the error message is below:</p>

<p>
        
        
            
            </p>

<pre><code>            &lt;EditItemTemplate&gt;
                &lt;asp:DropDownList ID="pictureEditCategories" runat="server" 
                    AppendDataBoundItems="True"
              DataSourceID="categoriesDataSource" 
                    DataTextField="Name" DataValueField="CategoryID" 
                    SelectedValue='&lt;%# Bind("CategoryID") %&gt;' ValidationGroup="PictureEdit" &gt;
                    &lt;asp:ListItem Value="" Text="--No 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;' ValidationGroup="PictureEdit" 
                     &gt;
                    &lt;asp:ListItem 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;/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>

<p>When i remove the SelectedValue='&lt;%# Bind("CategoryID") %>' from the item and edit template, I get the result for the picture below.
Please i will appreciate your help. </p>

<p>Please you can edit the code or explain it to me since im still learning ASP.net</p>

<p><img src="http://i.stack.imgur.com/778Ep.png" alt="alt text"></p>
