如何在按钮点击上找到gridview控件 [英] how to find gridview control on button click
本文介绍了如何在按钮点击上找到gridview控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含两个文本框的Gridview,在Gridview之外我有一个按钮我想要做的是当我点击按钮时我必须将数据存储在数据库中。
我是一个初学者,我google了它,但我没有找到任何参考链接相关这个
可以任何身体指导我正确的方式?
谢谢
I have a Gridview which Contains two Textboxes and outside the Gridview I have one button what i want to do is when i click the button i have to store that data in Database .
I'm a beginner ,I googled it but i don't find any reference links Related to this
can any body guide me in Right way?
Thanks
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
Height="55px" Width="305px" CellPadding="4" ForeColor="#333333"
GridLines="None" onselectedindexchanged="GridView1_SelectedIndexChanged" >
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:TemplateField HeaderText="id">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#Eval("SNO") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="name">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
推荐答案
按照方法查找文本框如下例所示(根据需要修改)
Follow the approach to find the Textboxes as per below example (Modify according to your need)
protected void Button1_Click(object sender, EventArgs e)
{
// Iterates through the rows of the GridView control
foreach (GridViewRow row in GridView1.Rows)
{
// Selects the text from the TextBox
// which is inside the GridView control
string textBoxText = ((TextBox)row.FindControl("TextBox1")).Text;
}
}
希望有帮助:)
Hope it helps :)
请参阅以下链接
如何在按钮事件中找到gridview的控件 [ ^ ]
refer below link
How to find control of gridview in button event[^]
这篇关于如何在按钮点击上找到gridview控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文