Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 dropdownlists in template columns 1

Status
Not open for further replies.

mariacri11

Programmer
Apr 9, 2003
22
CY
I have an editable datagrid whith template columns.
In two EditItemTemplates I have ddl.
I want the user to select the country from the first ddl and then the second ddl to display only the regions from that country.
I tried putting the code on the OnSelectedIndexChanged event of the first one but I can't access the second ddl from there.
Can anybody help me with this situation?

Thank you!
 
What you want is to get a reference to the DataGridItem (the current table row) that contains the drop down lists. The DataGrid's EditItemIndex should persist across postbacks as long as you don't reset it.

In the OnSelectedIndexChanged event handler for the Countries ddl, you will be able to easily get a reference to the object (sender) that raised the event. The tricky part is getting a reference to the DataGridItem that contains it. Once you have that, it's a simple call to FindControl("RegionsDDL") and you have full control over it.

I suspect that this can be done by "walking up" the heirarchy within the DataGrid. So once you have your reference to the country ddl, it is something like this: (C#)
Code:
DropDownList ddlCountry = (DropDownList)sender;
TableCell cell = (TableCell)ddlCountry.Parent;
DataGridItem item = (DataGridItem)cell.Parent;

DropDownList ddlRegion = (DropDownList)item.FindControl("ddlRegion");

ddlRegion.DataSource 
    = DataAccessLayer.GetRegions(ddlCountry.SelectedValue);
ddlRegion.DataBind();



 
Thank you!
It was ok, but then I faced other problem: befor using this when pressing edit button in the grid the selected value of the region ddl was the same as that from the non editable item.
I did this by using databinding but now it doesn't work. How can I achieve this again?

And another problem:
when entering the edit mode the region combo still has all the regions from all the countries.

Thank you again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top