H
Hagai Amiel via .NET 247
Hello There
I have created a fully programmatically datagrid
each time I press any button, the datagrid disappears when it posts back
how do I keep the grid on the screen without re-constructing it from scratch each time?
I have tryed saving it on session variables without any success
Following my code
private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack)
{
createColumns(); //creates the boundColumns of the grid
BindGrid();
Session["myDS"]=DS;
Session["myDG"]=myUserDG;
Session["myCom"]=comUsers;
}
else
{
DS=(DataSet)Session["myDS"];
myUserDG=(DataGrid)Session["myDG"];
comUsers=(SqlDataAdapter)Session["myCom"];
comUsers.Fill(DS, "USERS");
myUserDG.DataBind();
}
}
private void BindGrid()
{
myUserDG.DataSource=CreateDataSet();
myUserDG.DataMember="USERS";
myUserDG.DataBind();
}
private DataSet CreateDataSet()
{
connString=ConfigurationSettings.AppSettings["conn"];
con=new SqlConnection(connString);
comUsers=new SqlDataAdapter("getDetails",con);
comUsers.SelectCommand.CommandType=CommandType.StoredProcedure;
try
{
DS = new DataSet();
comUsers.Fill(DS, "USERS");
return DS;
}
catch(SqlException ex)
{
Response.Write("Errore retrieving Data:" + ex.Message.ToString() );
return null;
}
}
I have created a fully programmatically datagrid
each time I press any button, the datagrid disappears when it posts back
how do I keep the grid on the screen without re-constructing it from scratch each time?
I have tryed saving it on session variables without any success
Following my code
private void Page_Load(object sender, System.EventArgs e)
{
if (! IsPostBack)
{
createColumns(); //creates the boundColumns of the grid
BindGrid();
Session["myDS"]=DS;
Session["myDG"]=myUserDG;
Session["myCom"]=comUsers;
}
else
{
DS=(DataSet)Session["myDS"];
myUserDG=(DataGrid)Session["myDG"];
comUsers=(SqlDataAdapter)Session["myCom"];
comUsers.Fill(DS, "USERS");
myUserDG.DataBind();
}
}
private void BindGrid()
{
myUserDG.DataSource=CreateDataSet();
myUserDG.DataMember="USERS";
myUserDG.DataBind();
}
private DataSet CreateDataSet()
{
connString=ConfigurationSettings.AppSettings["conn"];
con=new SqlConnection(connString);
comUsers=new SqlDataAdapter("getDetails",con);
comUsers.SelectCommand.CommandType=CommandType.StoredProcedure;
try
{
DS = new DataSet();
comUsers.Fill(DS, "USERS");
return DS;
}
catch(SqlException ex)
{
Response.Write("Errore retrieving Data:" + ex.Message.ToString() );
return null;
}
}