Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I refer this link and work. I need one solution about link.

How to Save and Retrieve Dynamic TextBox values in GridView to SQL Server Database in ASP.Net Web Application. Second time running the same page perview stored values is not displaying in gridview. Kindly give the solution.

http://www.aspsnippets.com/Articles/Save-and-Retrieve-Dynamic-TextBox-values-in-GridView-to-SQL-Server-Database.aspx
Posted
Comments
syed shanu 18-Dec-14 2:40am    
The download is avaibalble in that link you can download the source and test it.

Did you try that program dis your data oif dynamic textbox saved in data base? IF saved means in save button click you need to rebidn the grid with new data.

1 solution

OK. So you want to get the textboxes of the GridView to be got filled automatically on second run if data is available in the database, right?

Follow this-
1. Do little changes to the TextBoxes as follows
ASP.NET
<asp:gridview id="Gridview1" runat="server" showfooter="true" xmlns:asp="#unknown">
            AutoGenerateColumns="false" onrowcreated="Gridview1_RowCreated">
            <columns>
            <asp:boundfield datafield="RowNumber" headertext="Row Number" />
            <asp:templatefield headertext="Header 1">
                <itemtemplate>
                    <asp:textbox id="TextBox1" runat="server" text="<%#Eval("Column1")"></asp:textbox>
                </itemtemplate>
            </asp:templatefield>
            <asp:templatefield headertext="Header 2">
                <itemtemplate>
                    <asp:textbox id="TextBox2" runat="server" text="<%#Eval("Column2")"></asp:textbox>
                </itemtemplate>
            </asp:templatefield>
            <asp:templatefield headertext="Header 3">
                <itemtemplate>
                     <asp:textbox id="TextBox3" runat="server" text="<%#Eval("Column3")"></asp:textbox>
                </itemtemplate>
                <footerstyle horizontalalign="Right" />
                <footertemplate>
                 <asp:button id="ButtonAdd" runat="server" text="Add New Row">
                        onclick="ButtonAdd_Click" />
                </asp:button></footertemplate>
            </asp:templatefield>
                 <asp:templatefield headertext="Header 3">
                <itemtemplate>
                    <asp:label id="Label1" runat="server" text="Click Me"></asp:label>
                </itemtemplate>
            </asp:templatefield>
            </columns>
        </asp:gridview>

2. Create a new method to get records as a datatable.
3. Call this method in the Page_Load() instead of SetInitialRow()

That's all :)

In case you need further assistance, please let me know :)
 
Share this answer
 
Comments
Abhishek Pant 1-Jan-15 10:05am    
+5ed,

Its a good solution.

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