在页面加载时在gridview标题模板中查找文本框控件 [英] find textbox control inside gridview header template on page load
本文介绍了在页面加载时在gridview标题模板中查找文本框控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< asp:GridView ID = GridView1 PageSize = 5 OnPageIndexChanging = GridView1_PageIndexChanging EnableModelValidation = true OnRowEditing = GridView1_RowEditing < span class =code-attribute> AutoGenerateColumns = False runat = 服务器 AllowPaging = True ShowHeaderWhenEmpty = True AllowSorting = True DataKeyNames = Id < span class =code-attribute> OnRowUpdating = GridView1_RowUpdating OnRowDataBound = GridView1_RowDataBound BackColor = #CCCCCC BorderColor = #999999 BorderStyle = 实体 BorderWidth = 3px CellPadding = 4 CellSpacing = 2 ForeColor = 黑色 >
< 列 >
< asp:TemplateField HeaderText = ID >
< HeaderTemplate >
< asp:TextBox ID = txtid runat = server CssClass = search_textbox 占位符 = Id > < / asp:TextBox >
< asp:LinkButton ID = lnkbtnid runat = server Text = Id ForeColor = 白色 > < / asp:LinkButton >
< / HeaderTemplate >
< ItemTemplate >
< asp:标签 ID = lblcustid runat = server 文字 =' <% #Eval( Id)%> ' > < / asp:标签 >
< / ItemTemplate >
< / asp:TemplateField >
我想在页面加载时找到标题模板文本框控件
解决方案
试试这个:
foreach (GridViewRow gdv in GridView1.Rows){
if (gdv.RowType == DataControlRowType。标题)
{
// 在此处查找控件。
TextBox txt =(TextBox)gdv.HeaderRow.FindControl( txt);
}
}
- 艾米
<asp:GridView ID="GridView1" PageSize="5" OnPageIndexChanging="GridView1_PageIndexChanging" EnableModelValidation="true" OnRowEditing="GridView1_RowEditing" AutoGenerateColumns="False" runat="server" AllowPaging="True" ShowHeaderWhenEmpty="True" AllowSorting="True" DataKeyNames="Id" OnRowUpdating="GridView1_RowUpdating" OnRowDataBound="GridView1_RowDataBound" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" CellSpacing="2" ForeColor="Black">
<Columns>
<asp:TemplateField HeaderText="ID">
<HeaderTemplate>
<asp:TextBox ID="txtid" runat="server" CssClass="search_textbox" placeholder="Id"></asp:TextBox>
<asp:LinkButton ID="lnkbtnid" runat="server" Text="Id" ForeColor="White"></asp:LinkButton>
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblcustid" runat="server" Text='<%#Eval("Id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
I want to find header template textbox control on page load
解决方案
Try this:
foreach(GridViewRow gdv in GridView1.Rows){ if (gdv.RowType == DataControlRowType.Header) { //Find the control here. TextBox txt = (TextBox)gdv.HeaderRow.FindControl("txt"); } }
--Amy
这篇关于在页面加载时在gridview标题模板中查找文本框控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文