DataGrid losing viewstate on postback when used in MultiPage control.

K

Ken Varn

I have two DataGrids that I want to use in a MultiPage control. Each
DataGrid is on a seperate PageView area within the MultiPage. One of the
DataGrids (OutputList) has a template column that contains a CheckBox web
server control. The other DataGrid (InputList) does not have any template
columns that use postback data.

In order to be able to use the VS.NET visual builder on the DataGrids, I
elected to not place them into the PageViews until run-time. However, for
some reason when I do this, the OutputList DataGird loses all of the items
in it on postback. If I do not add the DataGrids to the PageView, then it
works fine. The only difference I can see between the OutputList and
InputList datagrid is that if I remove the checkbox Template Column, then it
works fine. Does anyone have an explanation for this?

In addition, I tried putting the DataGrids into the PageView using the HTML
for the form and it works fine that way as well. The problem only seems to
occur when I add it progmatically.

At run-time I call the following code to place the DataGrid controls into
each PageView of the MultiPage control:

protected Microsoft.Web.UI.WebControls.MultiPage IOPages;
protected System.Web.UI.WebControls.DataGrid InputList;
protected System.Web.UI.WebControls.DataGrid OutputList;

private void Page_Load(object sender, System.EventArgs e)
{
PageView InputsPage;
PageView OutputsPage;

InputsPage = IOPages.FindControl("InputsPage") as PageView;

if (InputsPage != null)
{
InputsPage.Controls.Add(InputList);
}

OutputsPage = IOPages.FindControl("OutputsPage") as PageView;

if (OutputsPage != null)
{
OutputsPage.Controls.Add(OutputList);
}

if (!Page.IsPostBack)
{
// Dataset loaded here (omitted)

InputList.DataBind();
OutputList.DataBind();
}
}



-
-----------------------------------
Ken Varn
Senior Software Engineer
Diebold Inc.

EmailID = varnk
Domain = Diebold.com
-----------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top