Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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.NET
        <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" />
Posted
Updated 12-Dec-14 1:48am
v4
Comments
DamithSL 12-Dec-14 7:34am    
update the question with your aspx page gridview code and also include the code which explain how you bind data to gridview.
if you tried to something then why don't you include those code samples in your question?

Follow the approach to find the Textboxes as per below example (Modify according to your need)

C#
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 :)
 
Share this answer
 
Comments
King Fisher 12-Dec-14 7:44am    
my 5+ :)
Sanket Saxena 12-Dec-14 7:49am    
Thanks King :)
King Fisher 12-Dec-14 7:53am    
Welcome :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900