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

    i am using cascadiung dropdown

    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

    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.Items.FindByText(Assignment).Selected = true;

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

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



  2. Ivan Danchev
    Ivan Danchev avatar
    1301 posts

    Posted 06 Apr 2015 Link to this post


    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.
    Ivan Danchev

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

Back to Top