Hi,
I need to add data from textox1.text and textbox2.text to gridview.Clicking button.one by one.And to show them in gridview.
Thanks.
Data table
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Abhijit baruaRank #3,722 · 397 reputationPosted Jun 5, 2012, 5:13 AM EDT
Satyapriya NayakRank #47 · 31.5K reputationPosted Jun 5, 2012, 5:44 AM EDT
Try this...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="WebApplication16.WebForm3" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
namespace WebApplication16
{
[Serializable]
public class fields
{
public string name { get; set; }
public string address { get; set; }
}
public partial class WebForm3 : System.Web.UI.Page
{
List
protected void Button1_Click(object sender, EventArgs e)
{
string name = TextBox1.Text;
string address = TextBox2.Text;
fields f1 = new fields();
f1.name = TextBox1.Text;
f1.address = TextBox2.Text;
data.Add(f1);
ViewState["_data"] = data;
GridView1.DataSource = data;
GridView1.DataBind();
clear();
}
protected void Page_Load(object sender, EventArgs e)
{
data = ViewState["_data"] as List
if (data == null)
data = new List
}
void clear()
{
TextBox1.Text = "";
TextBox2.Text = "";
}
}
}
Thanks
If this post helps you mark it as answer