locked
'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items. RRS feed

  • Question

  • User1703251055 posted


    We use gridview for showing a data from table.It show fine in certain case like in table field dispostion is data and test but in table we put the string

    Ineligible Member/Member No Longer Enrolled - Spoke to Target and Wrong Number After Skip Tracing then it gives  error.

     'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.

    The following is snippest my code ,Can any please tell me where i am wrong.


      <asp:GridView ID="gvDispositionChange" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%"

    OnRowCommand="gvDispositionChange_RowCommand" OnRowDataBound="gvDispositionChange_RowDataBound" >
                        <Columns>
                            <asp:TemplateField HeaderText="REFID">
                               
                                <ItemTemplate>
                                    <asp:Label ID="lblREFID" runat="server" Text='<%# Bind("Refid") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                           
                            
                            <asp:TemplateField HeaderText="DISPOSITION" >
                               
                                <ItemTemplate>
                                    <asp:DropDownList ID="ddDisposition" runat="server" DataSourceID="SqlDataSource2"
                                DataTextField="DISPOSITION" DataValueField="DISPOSITION" SelectedValue='<%# Bind("Disposition") %>' Width="300px"
                                >
                            </asp:DropDownList>
                <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
                     ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT ID, Disposition FROM TblCallStatus">
               </asp:SqlDataSource>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Center" />
                            </asp:TemplateField>
                                                
                           
                         
                        </Columns>
                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <EditRowStyle BackColor="#999999" />
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    </asp:GridView>



    Monday, January 24, 2011 8:58 AM

Answers

  • User-1635004338 posted

    Hi shrishail_ashtage,

    For this error you get, the only reason can be that the bound value from the data source of GridView for "Disposition" field is not in the options of DropDownList from its own data source "SqlDataSource2". For example, if the options in DropDownList is 1,2,3, but the bound value in this row from GridView data source is 4. Then the error will come, because 4 is not in 1,2,3. Double check if this kind of condition exists such as null value or space in word.

    Thanks,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 26, 2011 3:20 AM

All replies

  • User-193293338 posted

    are you sure the error is coming from that section of code?   You do not have a DDL called "DropDownList1" in that section.  The only one I see is "ddDisposition"

     

    Monday, January 24, 2011 10:13 AM
  • User312496708 posted

    most probably the problem is that the data value for selection does not exists in the  datasource you are binding the value to.

    Monday, January 24, 2011 10:20 AM
  • User1703251055 posted

    Hello

              Thnks for reply

    yes data is ther inside the table,but it also gives the error.


    Tuesday, January 25, 2011 8:22 AM
  • User-193293338 posted

    please post the section of code that has DropDownList1 in it - aspx and code behind. 

    Tuesday, January 25, 2011 8:49 AM
  • User-1635004338 posted

    Hi shrishail_ashtage,

    For this error you get, the only reason can be that the bound value from the data source of GridView for "Disposition" field is not in the options of DropDownList from its own data source "SqlDataSource2". For example, if the options in DropDownList is 1,2,3, but the bound value in this row from GridView data source is 4. Then the error will come, because 4 is not in 1,2,3. Double check if this kind of condition exists such as null value or space in word.

    Thanks,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, January 26, 2011 3:20 AM