Assign Label value to dynamically generated ASP.Net GridView row on PageLoad using C#

Last Reply on Feb 27, 2018 02:36 AM By dharmendr

Posted on Feb 27, 2018 02:06 AM


reference to my Pervious Question I have added one label insted of textbox1 and i want to load the label value at the page load. I tried this

dr["Column1"] = Label1.Text;

it's working after I clicked AddNewRowToGrid() function. How can I load in the page load label value. 

drCurrentRow["Column1"] = Label1.Text;


      <asp:gridview ID="Gridview1" runat="server" ShowFooter="true"
            AutoGenerateColumns="false" onrowcreated="Gridview1_RowCreated">
            <asp:BoundField DataField="RowNumber" HeaderText="Row Number" />
            <asp:TemplateField HeaderText="Header 1">
                    <asp:Label ID="TextBox1" runat="server" Text=""></asp:Label>
            <asp:TemplateField HeaderText="Header 2">
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
            <asp:TemplateField HeaderText="Header 3">
                     <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                <FooterStyle HorizontalAlign="Right" />
                 <asp:Button ID="ButtonAdd" runat="server" Text="Add New Row"
                        onclick="ButtonAdd_Click" />
                    <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click">Remove</asp:LinkButton>
        <asp:Button ID="Button1" runat="server" Text="Save" onclick="Button1_Click" />
        <asp:Label ID="Label1" runat="server" Text="name"></asp:Label>


Posted on Feb 27, 2018 02:36 AM
irshad1231 says:
<asp:Label ID="TextBox1" runat="server" Text=""></asp:Label>

 To add Label value in page load you have to assign the Text property to the GridView TextBox like below.

<asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("Column1") %>'></asp:TextBox>