locked
dropdown list inside the gridview is showing error like drop down list has a selected value which is invalid in the list. RRS feed

  • Question

  • User1337950811 posted

    Hi,

    I have a drop down list inside the Grid View 

    That list will get loaded based on selected filter criteria. 

    First time it is getting loaded correctly and next time it is not loading but throwing error. 

    Please help me out to resolve this issue.

    Thanks.

    Wednesday, September 3, 2014 2:15 AM

Answers

  • User-417640953 posted

    Hi Pradeep,

    Thank you post the issue to our forum.

    As members mentioned before, this error means the SelectedValue you set as "<%# Eval("ResourceID") %>" sometimes

    not exist in the datasource '<%# FilterResourcesByRoleID(Eval("Role_ID").ToString()) %>'. What I suggest you to do is binding

    the dropdownlist datasource in the codebehind in GridView's OnRowDataBound event handler. Then you can check if the SelectedValue

    you want to set exist in the datasource. That will cause your program simple and healthy.

    Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 9, 2014 4:59 AM

All replies

  • User-1360095595 posted

    Your code, one way or another, is trying to set the value of the DLL to a value that doesn't exist. That is, you have a list of ListItem items that have a text/value, but the value you're trying to set the DDL to doesn't match with any of the items in your list.

    Wednesday, September 3, 2014 2:19 AM
  • User1337950811 posted

    If this is the case then my Drop Down List won get loaded for the first time.  Please find my code below inside the GRID

    <asp:DropDownList ID="ddlResource" runat="server" Width="200px" AutoPostBack="true" DataSource='<%# FilterResourcesByRoleID(Eval("Role_ID").ToString()) %>'
    DataTextField = "Resource_Name" DataValueField = "Resource_ID" AppendDataBoundItems="true" SelectedValue ='<%# Eval("ResourceID") %>' ValidationGroup='<%# ((GridViewRow) Container).RowIndex %>'>
    <asp:ListItem Text="--Select--" Value="0" Selected="True"></asp:ListItem>
    </asp:DropDownList>

    Thanks 

    Wednesday, September 3, 2014 2:38 AM
  • User1337950811 posted

    Selected Value ResourceID is present in the list. 

    Regards.

    Wednesday, September 3, 2014 3:08 AM
  • User-1360095595 posted

    Selected Value ResourceID is present in the list

    One of the value is NOT present in the list otherwise you wouldn't get this error. Maybe a null value, maybe a value that has an additional space character that you can't see, who know...

    Wednesday, September 3, 2014 4:02 AM
  • User1337950811 posted

    I hope the values in the data source property will get loaded into the DDL. Correct me if I am wrong.

    I have some of the values which are null in Recource_ID. 

    But this is loaded for all the other scenarios. Not working for only one Scenario. 

    Could you please advise me.

    Thanks

    Wednesday, September 3, 2014 4:08 AM
  • User-1360095595 posted
    SelectedValue ='<%# Eval("ResourceID").Equals(DBNull.Value) ? "0" : Eval("ResourceID") %>'

    Where "0" is the value specified for the first, "Please select", item in the list (which has a value of "0").

    Wednesday, September 3, 2014 4:22 AM
  • User1337950811 posted

    Hi,

    I have tried this. Then also I am getting the same error.

    'ddlResource' has a SelectedValue which is invalid because it does not exist in the list of items.
    Parameter name: value

    Thanks

    Wednesday, September 3, 2014 5:23 AM
  • User1337950811 posted

    Hi, 

    When I debug the code I could find that even when is present in the Eval("ResourceID") it is throwing the error. 

    My Application will load the Grid based on the values selected in the drop down list. 

    This issue is occurs for a particular value in the drop down list criteria. For other values this is working fine.

    Thanks

    Wednesday, September 3, 2014 5:32 AM
  • User79986525 posted

    Hi ,

    Bind you dropdown on rowdatabount event of gridview and assign selected value to dropdown over there .

    I hope you know how to find dropdow list on row databount  event.

     DropDownList ddlStrategy = (DropDownList)e.Row.FindControl("ddlStrategy");
     ddlStrategy.DataSource = ds.Tables[0];
                ddlStrategy.DataTextField = "Strategy";
                ddlStrategy.DataValueField = "Strategy";
                ddlStrategy.DataBind();
                ddlStrategy.Items.Insert(0, new ListItem("Strategy", "0"));
    ddlStrategy.SelectedValue=1;

    Wednesday, September 3, 2014 5:40 AM
  • User1337950811 posted

    Is there any way to do it on the Client Side. 

    I have a doubt like why this is working for all the other items and throwing error for only one search criteria

    Wednesday, September 3, 2014 5:54 AM
  • User79986525 posted

    Hi ,

    your Error 

    'ddlResource' has a SelectedValue which is invalid because it does not exist in the list of items.
    Parameter name: value

    Says that the value you provided as selectedvalue to dropdownList is not in the List .

    Please check the value come on datatable or whatever source you are using to bind the dropdown value (selectedvalue) and Gridview 

    Wednesday, September 3, 2014 8:36 AM
  • User1337950811 posted

    Hi,

    I am getting this error only for some search criteria. 

    When i load the data for some other criteria the value is getting loaded.

    Only for one selected value based on filter criteria it is not working 

    The ResourceID is present in the dataset. 

    Any further help please.

    regards,

    Thursday, September 4, 2014 6:31 AM
  • User-417640953 posted

    Hi Pradeep,

    Thank you post the issue to our forum.

    As members mentioned before, this error means the SelectedValue you set as "<%# Eval("ResourceID") %>" sometimes

    not exist in the datasource '<%# FilterResourcesByRoleID(Eval("Role_ID").ToString()) %>'. What I suggest you to do is binding

    the dropdownlist datasource in the codebehind in GridView's OnRowDataBound event handler. Then you can check if the SelectedValue

    you want to set exist in the datasource. That will cause your program simple and healthy.

    Thanks.

    Best Regards!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 9, 2014 4:59 AM