您的位置:首页 > 其它

寻找GridView中模板列中的控件

2009-07-03 00:57 381 查看
假如你在gridview中添加一个模板列,并 在模板列中存放了一个dropdownlist控件。那么,问题就是:你如何去操作这个dropdownlist控件????
//对于gridview控件:
System.Web.UI.WebControls.GridViewRow rows = (GridViewRow)((Control)sender).Parent.Parent;//获取对于ui层次结构中服务器控件的父控件的父控件的引用
DropDownList list = (DropDownList)rows.FindControl("DropDownList1");
//对于datagrid控件:
System.Web.UI.WebControls.DataGridItem item = (DataGridItem)((Control)sender).Parent.Parent;//获取对于ui层次结构中服务器控件的父控件的父控件的引用
DropDownList list = (DropDownList)rows.FindControl("DropDownList1");
其实运用的就是findcontrol方法。
System.Web.UI.WebControls.GridViewRow rows = (GridViewRow)((Control)sender).Parent.Parent;//获取对于ui层次结构中服务器控件的父控件的父控件的引用
对于这个还不理解。

VB.NET 写法如下:

Dim rows As System.Web.UI.WebControls.GridViewRow = CType(CType(sender, Control).Parent.Parent, GridViewRow) '//获取对于ui层次结构中服务器控件的父控件的父控件的引用
Dim dropList As DropDownList = CType(rows.FindControl("DropList_Level"), DropDownList)
Page.Response.Write("alert('" + dropList.SelectedValue.ToString + "')")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: