This is a migrated thread and some comments may be shown as answers.

How to set database value as selected in grid cascading drop

1 Answer 80 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Swapnil
Top achievements
Rank 1
Swapnil asked on 02 Apr 2015, 05:10 AM
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.

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 06 Apr 2015, 01:40 PM
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.

 
Tags
DropDownList
Asked by
Swapnil
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or