HOW TO PASS TEXTBOX VALUES TO GRIDVIEW WITHOUT
DATABASE
protected
void Page_Load(object
sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dtToGrid = new
DataTable();
dtToGrid.Columns.Add("ItemID",
typeof(int));
dtToGrid.Columns.Add("ItemName",
typeof(string));
Session["dtToGrid"] = dtToGrid;
}
}
protected void
Button1_Click1(object sender, EventArgs e)
{
DataTable dtToGrid = (DataTable)Session["dtToGrid"];
DataRow drToGrid = dtToGrid.NewRow();
drToGrid["ItemID"] =TextBox1.Text;
drToGrid["ItemName"] = TextBox2.Text.Trim();
dtToGrid.Rows.Add(drToGrid);
GridView1.DataSource = dtToGrid;
GridView1.DataBind();
}
No comments:
Post a Comment