Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
how we can pass value from textbox to datagridview on button click
Posted

XML
Hi,

In .aspx page :
<asp:textbox id="txtName" runat="server" xmlns:asp="#unknown"></asp:textbox>
<asp:button id="btnAddToGrid" runat="server" onclick="btnAddToGrid_Click" xmlns:asp="#unknown"></asp:button>
<asp:gridview id="gvTest" runat="server" autogeneratecolumn="false" xmlns:asp="#unknown">
       <asp:templatefield>
            <itemtemplate>
              <asp:lable id="lblName" runat="server" text="&lt;%#Eval("Name")%&gt;"></asp:lable>
</itemtemplate>
</asp:templatefield>
</asp:gridview>


In C# page :

private void On button click()
{
    DataTable dtTest=new DataTable();
    dtTest.Columns.Add("Name");
    dtTest.Rows.Add(txtName.Text.Trim());
    dtTest.AcceptChanges();
    gvTest.DataSource=dtTest;
    gvTest.DataBind();
}
 
Share this answer
 
v2
 
Share this answer
 
v3
 
Share this answer
 

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