DataGrid disappears on UpdateCommand

D

displacer

Hi,

I'm using a DataGrid with dynmically created colums.
(AutoGenerateColumns=false)
I call the DataGrid creation and data binding if !IsPostBack in Page_Load.
By clicking on Update my DataGrid disappears.

The strange this is: When I use AutoGenerateColumns=true (not using
dynmically created columns) everything works fine.

Can anybody help me out?
Tom
 
P

Philip Q [MVP]

displacer said:
Hi,

I'm using a DataGrid with dynmically created colums.
(AutoGenerateColumns=false)
I call the DataGrid creation and data binding if !IsPostBack in Page_Load.
By clicking on Update my DataGrid disappears.

The strange this is: When I use AutoGenerateColumns=true (not using
dynmically created columns) everything works fine.

I think this is because you are not binding on postbacks and the data is
being lost. AutoGenerateColumns will generate and bind the columns every
time the page loads.
 
T

tsz

you mean a call to DataBind()?
I tried to recreate the DataGrid on every Page_Load but the edit/update
commands don't work any more.
 
J

Juliet Choy [MVP]

You've said you are dynamically creating your columns. Since column
information are not persisted across view states, so you have to make
sure that you have execute the create column code in every postback. The
best place to do it would be in the LoadViewState() method of your page.

To see the explanation and an example, this article might help you:
http://msdn.microsoft.com/library/d...questionsaboutaspnetdatagridservercontrol.asp

Hope this help.

Best Regards,
Juliet Choy
Hong Kong
Microsoft MVP - ASP.NET
 
H

Harish Palaniappan

yes u should databind().. to solve the problem.. as philip Q says..

but u r doing it in the wrong time.. if u do a databind() on postback.. ur
edit or update command data (posted back) is ignored.
u should handle the postback event.. the Datagrid_edit() (if u named and
linked the event that way), and at the end of the code in this event, u shud
call databind()...

preferably like below:

private void Page_Load(object sender, System.EventArgs e)

{

if (!IsPostBack)

BindTaskGrid();

}

public void Task_Edit(Object s, DataGridCommandEventArgs e)

{

DataGrid1.EditItemIndex=e.Item.ItemIndex;

BindTaskGrid();

}

tsz said:
you mean a call to DataBind()?
I tried to recreate the DataGrid on every Page_Load but the edit/update
commands don't work any more.
 

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,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top