View state and Datagrid images

  • Thread starter Thread starter John
  • Start date Start date
J

John

I am using the ItemDataBound event on the datagrid to place relevant images
in the grid. However, when I press any button on the form which fires a
postback the state of the grid is kept but the images no longer appear as
the ItemDataBound event is no longer fired. The solution to this is to
refresh the grid with the original data using the page load event after
postback but then it loses the data that the user has already typed into the
grid pre-postback due to the grid being refreshed.

Anyone have any idea how to solve this?

My Code :
if (e.Item.Cells[7].Text!="Stock" & e.Item.Cells[7].Text!=" ")

{

if (Convert.ToInt32(e.Item.Cells[7].Text)<=0)

{

System.Web.UI.WebControls.Image imgGridImage =
(System.Web.UI.WebControls.Image)e.Item.Cells[5].Controls[1];

imgGridImage.ImageUrl="../images/OutStock.gif";

e.Item.Cells[5].Controls.Add(imgGridImage);

}

else

{

System.Web.UI.WebControls.Image imgGridImage =
(System.Web.UI.WebControls.Image)e.Item.Cells[5].Controls[1];

imgGridImage.ImageUrl="../images/InStock.gif";

e.Item.Cells[5].Controls.Add(imgGridImage);

}

}
 
I tried rebinding the grid in the page load event with or without a postback
but then it loses the values which have been entered into a text box column
before the postback.

Is there no way to keep the images being displayed on the grid when the page
is reloaded? All the other information is held in the view state and
displayed correctly. Surely there must be a solution to this somewhere....?

Please, help!!!
 
Back
Top