如何从gridview页脚c#中的文本框中获取值?
如标题+如何处理按钮单击哪个按钮也在GridView页脚中 aspx文件似乎是这样的如何从gridview页脚c#中的文本框中获取值?,c#,asp.net,C#,Asp.net,如标题+如何处理按钮单击哪个按钮也在GridView页脚中 aspx文件似乎是这样的 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="id" EnableModelValidation="True" ForeColor="#333333" GridLines="None"
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="id" EnableModelValidation="True"
ForeColor="#333333" GridLines="None"
onrowcancelingedit="GridView1_RowCancelingEdit1"
onrowediting="GridView1_RowEditing1"
onrowupdating="GridView1_RowUpdating1" AllowPaging="True"
onrowdeleting="GridView1_RowDeleting"
onpageindexchanging="GridView1_PageIndexChanging" Height="322px"
ShowFooter="True" onselectedindexchanged="GridView1_SelectedIndexChanged" >
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="ID" Visible="False" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField>
<FooterTemplate>
<asp:TextBox ID="txtName" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:TemplateField>
<FooterTemplate>
<asp:TextBox ID="txtLastName" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="DriveLic" HeaderText="DriveLicense" />
<asp:TemplateField>
<FooterTemplate>
<asp:TextBox ID="txtDriveLicense" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="country" HeaderText="Country" />
<asp:TemplateField>
<FooterTemplate>
<asp:TextBox ID="txtWoj" runat="server" />
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" />
<asp:TemplateField>
<FooterTemplate>
<asp:Button ID="ButtonOK" Text="Confirm" runat="server" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
在
GridView\u row命令中
可以通过GridView1.FooterRow.FindControl
方法访问页脚控件
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Insert", StringComparison.OrdinalIgnoreCase))
{
TextBox txtSomeNewValue = ((TextBox)GridView1.FooterRow.FindControl("txtSomeNewValue"));
string theTextValue = txtSomeNewValue.Text;
}
}
更新:将代码包装在一个if块中,该块检查
commandname
是否符合预期。此事件还用于删除、编辑等,因此,如果不将其包装在本文中,您可能会运行一个您不打算运行的事件的代码。我必须从GridView页脚的文本框中插入数据,再加上一个按钮,当我单击此按钮时,它应该从此文本框中插入数据库值。这就是我想知道的:)但是如何处理事件按钮点击因为它与此文本框位于同一位置在GridView页脚内放置一个LinkButton
按钮,设置CommandName=“Insert”
,然后单击按钮,将触发rowcommanad
事件。但我必须使用普通按钮:(@harry180,当然只需设置CommandName=“Insert”
和GridView_row命令
事件将在单击页脚行内的按钮时触发。确定:)主题可以关闭:)我知道我想要什么:)谢谢WAqas Raja:)