代码改变世界

GridView中DropDownList联动

2010-07-30 00:26  Jun2009  阅读(479)  评论(0编辑  收藏  举报

1.在GridView模板列中添加DropDownList并设置AutoPostback属性为true

2.再在DropDownList的SelectedIndexChanged事件里写下面几句话。

DropDownList ddl = (DropDownList)sender; //得到当前的DropDownList
GridViewRow gvr = (GridViewRow)ddl.NamingContainer; //获取对DropDownList的容器引用

//得到gvr后就好办了查找下面的子控件。
DropDownList ddl2 = (DropDownList)gvr.FindControl("DDl2")
再给ddl2绑定数据

跟小D每日学口语