Click here to Skip to main content
12,508,014 members (52,205 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: ASP.NET
I have taken textbox in gridview and want to save textbox value in database and then fetch it in textbox of gridview itself

//source code

<asp:GridView ID="GrdATCart" AutoGenerateColumns="false" runat="server"
            onrowcommand="GrdATCart_RowCommand"
            onselectedindexchanged="GrdATCart_SelectedIndexChanged">
    <Columns>
        <asp:TemplateField HeaderText="Quantity">
            <ItemTemplate>
                <asp:TextBox ID="TxtATquantity" runat="server" Width="60px"></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>
Posted 13-Dec-12 23:58pm
v3
Comments
Tadit Dash 14-Dec-12 8:08am
   
Tell me in which event in code behind you want to store the data?
Please post the code behind functions related to GridView, where you want to store the textbox data?
rahkan 15-Dec-12 8:46am
   
Is there a reason the textbox is not bound to any data? Normally you'll have something like Text='<%# Bind("Quantity") %>' inside of the textbox
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hi,

Try this on button click and fetch value from textbox

foreach (GridViewRow row in gridview1.Rows) 
        {
            if (row.RowType == DataControlRowType.DataRow) 
            {
                Textbox txt = (Textbox) row.FindControl("txt1");
                if (txt != null )
                {
                    string value=txt.Text;
//Here you can write your query to insert into database
                }
            }
        }
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160927.1 | Last Updated 19 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100