C# 如何在我的代码隐藏C中引用gridview中的文本框
我发现的所有例子都没有帮助。我在gridview的页脚中有一个文本框,名为txtmycerage。在我的代码隐藏中,我只想引用那个文本框C# 如何在我的代码隐藏C中引用gridview中的文本框,c#,asp.net,gridview,C#,Asp.net,Gridview,我发现的所有例子都没有帮助。我在gridview的页脚中有一个文本框,名为txtmycerage。在我的代码隐藏中,我只想引用那个文本框 a = txtMyCoverage.Text; 我试过了 gvLimit.FindControl("txtMyCoverage").ToString(); 但它返回空引用。谢谢你的帮助 这是我的网格 <asp:GridView Width="100%" ID="gvLimits" CssClass="gridView no_min_width" ru
a = txtMyCoverage.Text;
我试过了
gvLimit.FindControl("txtMyCoverage").ToString();
但它返回空引用。谢谢你的帮助
这是我的网格
<asp:GridView Width="100%" ID="gvLimits"
CssClass="gridView no_min_width"
runat="server"
AutoGenerateColumns="False"
CellPadding="2" ShowFooter="true"
DataKeyNames="PolicyLimitID, LimitID"
HorizontalAlign="Center"
OnRowDataBound="gvLimits_RowDataBound">
<RowStyle HorizontalAlign="Center" />
<Columns>
<asp:TemplateField HeaderText="Coverage">
<ItemTemplate>
<asp:Label ID="txtLimitLetter" runat="server" Width="20px" CssClass="center" Text='<%# Bind("Limit.LimitLetter") %>' Enabled="false" ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtMyCoverage" runat="server" Width="50px" CssClass="center" ></asp:TextBox>
</FooterTemplate>
</Columns>
</asp:GridView>
如果您使用如下文本框:
<asp:TemplateField HeaderText="Coverage">
<ItemTemplate>
<asp:Label ID="txtLimitLetter" runat="server" Width="20px" CssClass="center" Text='<%# Bind("Limit.LimitLetter") %>' Enabled="false" ></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtMyCoverage" runat="server" Width="50px" CssClass="center" ></asp:TextBox>
</FooterTemplate>
或
您可以查看GridView行
foreach(GridViewRow row in GridView2.Rows)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
TextBox txtLimitLetter=(TextBox)e.Row.FindControl("txtLimitLetter");
}
}
为什么要尝试将控件转换为字符串?能否显示如何在标记中定义txtMyCoverage您是否有runat=以及是否分配了ID。。?请提供/显示更多信息向我们展示您的HTML代码DataGrid。您添加了runat=Server属性了吗?我添加了网格代码..去掉了其他列,这样就不会太长了@MelanciaUK我只是想从那个文本框中获取文本。谢谢@Ganesh_Devlekar解决了这个问题!
foreach(GridViewRow row in GridView2.Rows)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
TextBox txtLimitLetter=(TextBox)e.Row.FindControl("txtLimitLetter");
}
}