GridView编辑状态下DropDownList的联动

代码
protected   void  ddlDw_SelectedIndexChanged( object  sender, EventArgs e)
        {
            DropDownList ddlDw 
=  sender  as  DropDownList;
            GridViewRow gvRow 
=  ddlDw.NamingContainer  as  GridViewRow;
            CheckBoxList chklXdzz 
=  gvRow.FindControl( " chklXdzz " as  CheckBoxList;

            
string  dwbh  =  gvUser.DataKeys[gvRow.RowIndex].Values[ 1 ].ToString();
            
string  curDwbh  =  ddlDw.SelectedValue;
            
if  (dwbh  !=  curDwbh)
            {
                BindXdzz(chklXdzz, curDwbh);
            }
            
else
            {
                
string  xdzzbh  =  gvUser.DataKeys[gvRow.RowIndex].Values[ 2 ].ToString();
                BindXdzz(chklXdzz, curDwbh, xdzzbh);
            }
        }

这里使用NamingContainer获取上一级数据容器,再通过该容器获取兄弟控件。

注意别忘记将ddlDw的AutoPostback属性设置为True。

你可能感兴趣的:(GridView)