Want to become a Vibe Coder? Join Vibe Coding Training here
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
Add TextBox Values to GridView in ASP.NET on Button Click
WhatsApp
Pintoo Yadav
Aug 27
2015
22.6
k
0
1
public
partial
class
WebForm2: System.Web.UI.Page {
DataTable dt =
null
;
protected
void
Page_Load(
object
sender, EventArgs e) {
if
(!IsPostBack) {
if
(ViewState[
"Details"
] ==
null
) {
DataTable dataTable =
new
DataTable();
dataTable.Columns.Add(
"Name"
);
dataTable.Columns.Add(
"Address"
);
ViewState[
"Details"
] = dataTable;
}
}
}
protected
void
Button1_Click(
object
sender, EventArgs e) {
string
str = txtname.Text.Trim();
string
str1 = TextBox1.Text.Trim();
dt = (DataTable) ViewState[
"Details"
];
dt.Rows.Add(str, str1);
ViewState[
"Details"
] = dt;
GridView1.DataSource = dt;
GridView1.EmptyDataText =
"Name"
;
GridView1.EmptyDataText =
"Address"
;
GridView1.DataBind();
}
}
C#
ASP.NET
TextBox
GridView
Up Next
Add TextBox Values to GridView in ASP.NET on Button Click