Dear All,
This Demo shows you how to bind TextBox value to Grid without using Database
Eg.
Ø Suppose that u have 3 TextBox and one Button Control and Grid
Ø TextBox1 for FirstName, TextBox2 for LastName and TextBox3 for Id
Ø Once u click on button the data get added to Grid Row
Ø Then on next button click second new row get added to row
Ø And so on…..
C# Code:
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;
public partial class TxtBoxDemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("First Name");
DataColumn dc1 = new DataColumn("Last Name");
DataColumn dc2 = new DataColumn("Id");
dt.Columns.Add(dc);
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
ds.Tables.Add(dt);
Session["data"] = ds;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DataSet ds = (DataSet)Session["data"];
DataRow dr = ds.Tables[0].NewRow();
dr[0] = txtFirstName.Text.Trim();
dr[1] = txtLastName.Text.Trim();
dr[2] = txtId.Text.Trim();
ds.Tables[0].Rows.Add(dr);
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
Dude,
ReplyDeleteThank you so much... :)
thank.........
ReplyDeletehow can i edit,update this values in gridview
ReplyDeleteHi Guys ...
ReplyDeletefollow below link for more post..
http://asp.velocitysolution.com/Home/Index.aspx