|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Data Grid Disappears after postbackI 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; } } ------------------------------- From: Hagai Amiel ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>goP52tlzS0uYc+ab4puADg==</Id> Hello,
Try placing createColumns() outside the IsPostBack condition. You can do the databind on the initial page load, but you'll need to re-create your dynamic grid every time. - Mike Hagai Amiel via .NET 247 wrote: Show quoteHide quote > Hello There > I have created a fully programmatically datagrid > each time I press any button, the datagrid disappears when it posts back |
|||||||||||||||||||||||