且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

gridview的行编辑 - 动态绑定到一个DropDownList

更新时间:2022-05-30 02:47:52

很容易...你就错了,因为该事件的控制是不存在的:

Quite easy... You're doing it wrong, because by that event the control is not there:

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow && 
        (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
    { 
        // Here you will get the Control you need like:
        DropDownList dl = (DropDownList)e.Row.FindControl("ddlPBXTypeNS");
    }
}

也就是说,它只会有效期为的DataRow (实际数据行),如果它在修改模式..因为你只有一次编辑一行。在 e.Row.FindControl(ddlPBXTypeNS)只能找到您想要的控制。

That is, it will only be valid for a DataRow (the actually row with data), and if it's in Edit mode... because you only edit one row at a time. The e.Row.FindControl("ddlPBXTypeNS") will only find the control that you want.