寻找GridView中模板列中的控件
生活随笔
收集整理的這篇文章主要介紹了
寻找GridView中模板列中的控件
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
假如你在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 + "')")
??????? 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 + "')")
轉載于:https://blog.51cto.com/liweibird/172526
總結
以上是生活随笔為你收集整理的寻找GridView中模板列中的控件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 公司正式宣布创业失败!
- 下一篇: 铁钉的blog地址 http://nai