GridView: Linked DropDownList

S

sck10

Hello,

I am using a GridView with 2 dropdown boxes. I would like to update the
second dropdown based on the first dropdown selection. Any help with this
would be appreciated.

Thanks in advance, sck10
 
A

Andrew Robinson

You can do this by setting AutoPostback to true on your first dropdownlist
and handling the OnSelectedIndexChanged event. Within this code, you can
update the other dropdownlist. Here is some example code that I used to
update label controls based on dropdownlist. You should be able to do the
same with your secondary DDL:


protected void DropDownListItem_SelectedIndexChanged(object sender,
EventArgs e) {

int itemID =
int.Parse(((DropDownList)GridViewMain.FooterRow.FindControl("DropDownListItem")).SelectedValue);



item = new ItemData().Get(itemID);



((Label)GridViewMain.FooterRow.FindControl("LabelCode")).Text =
item.Code;

((Label)GridViewMain.FooterRow.FindControl("LabelDescription")).Text =
item.Description;

((Label)GridViewMain.FooterRow.FindControl("LabelNote")).Text =
item.Note;


}


Hope this gets you going in the right direction.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top