Hi,
I want to add columns and then bind rows using Data table and show in Grid view without using Database(DONE).
After that I want a VIEW/EDIT functionality means if I click any row then the data of row should be in their respective controls(textboxes) and I can update them and again save.
For better understand, I am giving my .cs and .aspx page code.
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
if (!this.IsPostBack)
{
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Name"), new DataColumn("Address") });
ViewState["Customers"] = dt;
this.BindGrid();
}
}
protected void BindGrid()
{
GridView1.DataSource = (DataTable)ViewState["Customers"];
GridView1.DataBind();
}
protected void btnAdd_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)ViewState["Customers"];
dt.Rows.Add(txtName.Text.Trim(), txtAddress.Text.Trim());
ViewState["Customers"] = dt;
this.BindGrid();
txtName.Text = string.Empty;
txtAddress.Text = string.Empty;
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
==================================================================
| |
Regards:
Anurag Singh

Anurag SinghPosted Sep 18, 2015, 4:45 AM
Upendra Pratap ShahiPosted Sep 18, 2015, 4:41 AM
Anurag SinghPosted Sep 18, 2015, 4:22 AM
Upendra Pratap ShahiPosted Sep 18, 2015, 2:57 AM