How to set database value as selected in grid cascading drop

2 posts, 0 answers
  1. Swapnil
    Swapnil avatar
    96 posts
    Member since:
    Aug 2013

    Posted 02 Apr 2015 Link to this post

    Hi,
    i am using asp.net cascadiung dropdown
    lists.
    assignment
    2.task




    i have bind data to both dropdownlist and succesfully write insert code.
    But my problem is when i next time go that page grid must show previously inserted data.
    For this i can able to bind assignment dropdown but my task dropdown is not binding properly.
    It shows all data for that current assignment(not showing which task is allready inserted for that
    assignment.)

    i tried following code for assignment
    and task binding.

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType ==DataControlRowType.DataRow)
    {
    DropDownList ddlAssignment = (e.Row.FindControl("ddlAssignment") as DropDownList);
    string Assignment =(e.Row.FindControl("lblAssignment") as Label).Text;
    ddlAssignment.ClearSelection();
    ddlAssignment.Items.FindByText(Assignment).Selected = true;

    DropDownList ddlTask = (e.Row.FindControl("ddlTask") as DropDownList);
    string Task = (e.Row.FindControl("lblTask") as Label).Text;
    ddlTask.ClearSelection();
    ddlTask.Items.FindByText(Task).Selected = true;

    i also tried
    ddlTask.Items.FindByValue(Task).Selected = true;

    }
    }

    Thanks.

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    834 posts

    Posted 06 Apr 2015 Link to this post

    Hello,

    Are you trying to achieve something close to the scenario we have in our Related DropDownLists demo, where the DropDownList controls are bound to one database and the selection in one of them affects the items displayed in the other?

    Please, review the code of the demo, note that the AutoPostBack property of the first and second DropDownLists is set to "true".

    In case it doesn't help you find and fix the problem in your code, I am attaching the demo isolated as a sample project, so you can try to reproduce the issue in it and post your modifications.
     
    Regards,
    Ivan Danchev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top