TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Add TextBox Values to GridView in ASP.NET on Button Click
Pintoo Yadav
Aug 27
2015
Code
22.3
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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