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.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Jun 5, 2012, 9:44 AM
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
Abhijit baruaPosted Jun 5, 2012, 9:13 AM