Click here to Skip to main content
15,878,945 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

XML
<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
v3
Comments
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

 
Share this answer
 
 
Share this answer
 
Hi,

Try this on button click and fetch value from textbox

C#
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
                }
            }
        }
 
Share this answer
 
v2

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