GridView RowDataBound Event Issues

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
 
R

ryan.mclean

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
 
T

Teemu Keiski

RowCreated runs also on hwne grid is restored from viewstate (it also runs
just before RowdataBound)
 
R

ryan.mclean

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
 
Joined
Apr 23, 2008
Messages
1
Reaction score
0
Remove control from gridview's datarow

Hello everyone!

I was looking for solution on how to remove the control forom the datarow and ran across this post. I found a fix and just want to share it with everyone. I hide the control instead of removing it. See code below.


ImageButton img = e.Row.FindControl("collapse_expand") as ImageButton;
img.Attributes.Add("style", "display:none;");

Hope this helps!

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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top