GridView RowDataBound Event Issues

  • Thread starter Thread starter ryan.mclean
  • Start date Start date
R

ryan.mclean

Hello everyone, I'm in a bind, and I hope somebody can point me in the
right direction.

I have a gridview that is bound when it is not a postback. When the
grid is bound, I remove the contents of a cell based on criteria

e.g.
Protected Sub gvOffSiteHoursRequests_RowDataBound(ByVal sender As
Object, _
ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) _
Handles gvOffSiteHoursRequests.RowDataBound
if (str = "example) then
e.Row.Cells(0).Controls.Clear()
end if


This works great EXCEPT when another control on the same page has a
postback, the controls are un-cleared, the grid is possibly reloaded
from viewstate and does not fire my RowDataBound event because the
event was not called. This could be remedied by binding the grid every
time there is a postback, but this would mess up the editing etc.

I hope that makes sense. Please let me know if you have any ideas.

Thank you and have a great day,
Ryan
 
I got around it by doing this:

if (Page.IsPostBack And
Request.Form("__EVENTTARGET").IndexOf("gvOffSiteHoursRequests") = -1)
then

LoadDate

Seems very dirty, if anyone has a better solution, I would appreciate
it!

Thanks,
Ryan
 
RowCreated runs also on hwne grid is restored from viewstate (it also runs
just before RowdataBound)
 
Hello Teemu, great idea! That will be much better then what I was
using. All these new events to learn about. Thank you very much. Have a
great weekend,
Ryan
 
Back
Top