Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid OnItemDataBound firing on postback

Status
Not open for further replies.

meckeard

Programmer
Aug 17, 2001
619
US
All,

I have a datagrid that appears to be calling the OnItemDataBound event twice - once when the page loads and again when it posts.

My page_load event does check for postback, like so:

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
LoadAllBooks();
}
}

This part works fine but when I click a button to do a postback, the OnItemDataBound event appears to fire again as it does some edits to the data in the datagrid and I can visually see some changes.

It doesn't appear to reload the datagrid; viewstate is intact and the checkboxes that I check prior to postback are retained.

Here's the shortened version of the OnItemDataBound event:

public void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
}

Commenting out the code in the OnItemDataBound event prevents the changes.

What am I missing? Is there something wrong with the OnItemDataBound event that anyone can see? This is the first time I've seen this.

Thanks,
Mark
 


appears to fire again as it does some edits to the data in the datagrid and I can visually see some changes.

If you're seeing changes in the datagrid, a rebinding is happening. Check to see if your update routine is rebinding the datagrid after an update occurs.




Mark

"You guys pair up in groups of three, then line up in a circle."
- Bill Peterson, a Florida State football coach
 
Mark,

It's not. That's the odd part.

I can place a response.write or some other visual queue in the OnItemDataBound event and it won't fire twice but it definitely does.

From what I can tell, this has to do with viewstate an the page trying to restore what it originally changed but I don't know how to prevent it from happening.

Thanks,
Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top