Jyoti Jodha

Jyoti Jodha

  • NA
  • 1.7k
  • 406.4k

how to use "IsPostBack" & ViewState in c# windows appli..

Apr 5 2017 3:54 AM
public Form2()
{
InitializeComponent();
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Name"), new DataColumn("Country") });
ViewState["Customers"] = dt;
this.BindGrid();
}
}
 
protected void BindGrid()
{
dataGridView.DataSource = (DataTable)ViewState["Customers"];
dataGridView.DataBind();
}
 
Error show in red highlight 
 

Answers (6)