Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
How do I preserve a value entered in a TextBox inside a gridview's templatefield when the gridview gets databound again?
Can anyone tell me why? And maybe help me in finding a solution?
for example i Click on A button and click event is Gridview1.DataBind() but we lose all values on TextBoxes.

let me explain more , when a user send a new comment, i will broadcast a message ( with signalr) to all other users to update their Gridviews ( when a client get broadcast message button1_Click, will be call by a jquery ). my problem is if other users are typing new comments on their textboxes will lose their typed comments

ASP.NET
 <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
    </Triggers>

    <ContentTemplate>
        <%--post GridView--%>
        <asp:GridView ID="posts" runat="server">
            <Columns>
                <asp:TemplateField>
                    <ItemTemplate>
                        <%--Comments Gridview--%>
                        <asp:GridView ID="comments" runat="server"></asp:GridView>
                        <%--a Textbox and bUtton For sending new Comment--%>
                        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                        <asp:Button ID="Button1" runat="server" Text="Button" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </ContentTemplate>
</asp:UpdatePanel> 


    protected void Button1_Click(object sender, EventArgs e)
{
    posts.DataSource = GetData();
    posts.DataBind();
}
Posted
Updated 28-Jun-14 6:31am
v2
Comments
superselector 30-Jun-14 8:44am    
hi ,

U probably have to save the gridview data to a datatable by looping through each row for each cell

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