GridView RowDataBound Event Issues

Discussion in 'ASP .Net' started by ryan.mclean@gmail.com, Sep 2, 2006.

  1. Guest

    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
     
    , Sep 2, 2006
    #1
    1. Advertising

  2. Guest

    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


    wrote:
    > 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
     
    , Sep 2, 2006
    #2
    1. Advertising

  3. Teemu Keiski Guest

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

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke

    <> wrote in message
    news:...
    >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
    >
    >
    > wrote:
    >> 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

    >
     
    Teemu Keiski, Sep 3, 2006
    #3
  4. Guest

    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

    Teemu Keiski wrote:
    > RowCreated runs also on hwne grid is restored from viewstate (it also runs
    > just before RowdataBound)
    >
    > --
    > Teemu Keiski
    > ASP.NET MVP, AspInsider
    > Finland, EU
    > http://blogs.aspadvice.com/joteke
    >
    > <> wrote in message
    > news:...
    > >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
    > >
    > >
    > > wrote:
    > >> 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

    > >
     
    , Sep 3, 2006
    #4
  5. key.le

    Joined:
    Apr 23, 2008
    Messages:
    1
    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!

     
    key.le, Apr 23, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. K B
    Replies:
    2
    Views:
    5,209
    Jan Hyde
    Jun 1, 2006
  2. Mike P
    Replies:
    0
    Views:
    5,031
    Mike P
    Jun 2, 2006
  3. mark4asp
    Replies:
    2
    Views:
    3,031
    meerhassan
    Oct 28, 2010
  4. Julia B
    Replies:
    0
    Views:
    1,407
    Julia B
    Mar 3, 2009
  5. Julia B
    Replies:
    0
    Views:
    3,199
    Julia B
    Mar 17, 2009
Loading...

Share This Page