GridView - two clicks needed to enter in-place editing

Discussion in 'ASP .Net' started by Hrvoje Vrbanc, Nov 25, 2007.

  1. Hello all,

    I've encountered a very strange problem: I have a GridView control on an
    ..aspx page that displays data correctly (in any case; with autogenerated
    columns or with using item templates).

    I added "Edit, Update, Cancel" command button to the GridView but when I
    click on "Edit" nothing happens. I have to click the same button again and
    only then the row displays EditItem template.

    The same happens when I press, e.g. "Cancel" button - it takes two clicks to
    enter normal GridView display mode.

    I tried it on two machines and on both VS development server and full IIS
    and it's always the same. It's very strange.

    Is it some sort of a trivial problem and I'm somehow missing something
    obvious?

    Thank you in advance,
    Hrvoje
     
    Hrvoje Vrbanc, Nov 25, 2007
    #1
    1. Advertising

  2. Hrvoje Vrbanc

    Scott M. Guest

    Have you written any custom code for your GridView? This behavior is
    usually associated with calling DataBind incorrectly and/or turning off
    ViewState for the control.

    Try another test, but this time don't change any properties of the GridView
    (not even its looks) and just enable Edit, Update, & Cancel via the smart
    tag. See if this works properly.


    "Hrvoje Vrbanc" <> wrote in message
    news:...
    > Hello all,
    >
    > I've encountered a very strange problem: I have a GridView control on an
    > .aspx page that displays data correctly (in any case; with autogenerated
    > columns or with using item templates).
    >
    > I added "Edit, Update, Cancel" command button to the GridView but when I
    > click on "Edit" nothing happens. I have to click the same button again and
    > only then the row displays EditItem template.
    >
    > The same happens when I press, e.g. "Cancel" button - it takes two clicks
    > to enter normal GridView display mode.
    >
    > I tried it on two machines and on both VS development server and full IIS
    > and it's always the same. It's very strange.
    >
    > Is it some sort of a trivial problem and I'm somehow missing something
    > obvious?
    >
    > Thank you in advance,
    > Hrvoje
    >
     
    Scott M., Nov 25, 2007
    #2
    1. Advertising

  3. Thanks!
    However, I have tried a "basic set up" and had the same problems.
    I have inserted a GridView, changed nothing and added just two events in the
    codebehind (beside the code necessary to create, fill and bind the dataset):

    Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles
    GridView1.RowCancelingEdit

    GridView1.EditIndex = -1

    End Sub

    Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As
    System.Web.UI.WebControls.GridViewEditEventArgs) Handles
    GridView1.RowEditing

    GridView1.EditIndex = e.NewEditIndex

    End Sub



    Maybe that's because there's no real code beside index determination?



    Thank you,

    Hrvoje





    "Scott M." <> wrote in message
    news:...
    > Have you written any custom code for your GridView? This behavior is
    > usually associated with calling DataBind incorrectly and/or turning off
    > ViewState for the control.
    >
    > Try another test, but this time don't change any properties of the
    > GridView (not even its looks) and just enable Edit, Update, & Cancel via
    > the smart tag. See if this works properly.
    >
    >
    > "Hrvoje Vrbanc" <> wrote in message
    > news:...
    >> Hello all,
    >>
    >> I've encountered a very strange problem: I have a GridView control on an
    >> .aspx page that displays data correctly (in any case; with autogenerated
    >> columns or with using item templates).
    >>
    >> I added "Edit, Update, Cancel" command button to the GridView but when I
    >> click on "Edit" nothing happens. I have to click the same button again
    >> and only then the row displays EditItem template.
    >>
    >> The same happens when I press, e.g. "Cancel" button - it takes two clicks
    >> to enter normal GridView display mode.
    >>
    >> I tried it on two machines and on both VS development server and full IIS
    >> and it's always the same. It's very strange.
    >>
    >> Is it some sort of a trivial problem and I'm somehow missing something
    >> obvious?
    >>
    >> Thank you in advance,
    >> Hrvoje
    >>

    >
     
    Hrvoje Vrbanc, Nov 25, 2007
    #3
  4. Hrvoje Vrbanc

    Scott M. Guest

    Yes, as suspected the problem is in your code, and is a DataBind call
    problem.

    You didn't provide your complete code that fills and binds (and is part of
    the problem), but I can explain what to do anyway.

    You only want to be calling the Databind method once per page call and it
    must be done at the "right" time. I suspect your call is in your Page_Load
    event and *not* wrapped in a test for a postback, as it should be. Your
    filling and binding code should look something like this:

    Sub Page_Load()
    'code to connect and fill
    If Not IsPostBack Then
    'Databinding should be the last thing you do to your GridView
    'Since we know this code only runs the first time your page is being
    loaded,
    'we know that it's not being loaded as a result of any kind of
    GridView user
    'manipulation (like a sort, select, edit, or page change)
    GridView.DataBind
    End If
    End Sub

    When your page is loading for the first time, your event handlers for
    selecting, sorting, editing and paging are not going to be called because
    how could a user be doing such things if they haven't even received the page
    for the first time?

    But, what if the page is loading NOT for the first time? Then, we have to
    ask *why* would the page be loading for a subsequent time? The answer is
    that the user initiated this subsequent page call by sorting, selecting,
    editing, or paging the GridVeiw, in which case, Page_Load will NOT be the
    last page event to fire in these cases. If you had been binding your
    GridView in Page_Load for every page call (as I suspect you have been
    doing), then you are binding your GridView before your code is done working
    with it (sure Page_Load is done, but now we've got to execute the sort,
    select, edit, paging event handlers).

    So, in PostBack situations, we don't want to bind to the GridView yet, we
    want to do it when we are done configuring the GridView for this current
    page display. This means that in EACH of your GridView event handlers, the
    LAST command should be GridVeiw.DataBind(). For example:

    Sub GridView1_RowCancelingEdit(ByVal . . .) Handles
    GridView1.RowCancelingEdit
    GridView1.EditIndex = -1
    GridView1.DataBind()
    End Sub

    Sub GridView1_RowEditing(ByVal . . .) Handles GridView1.RowEditing
    GridView1.EditIndex = e.NewEditIndex
    GridView1.DataBind()
    End Sub

    This way we know the following:
    1. The first time the page loads, the LAST thing done to the GridView
    is DataBind in Page_Load
    2. Any subsequent time the page loads, the LAST thing done to the
    GridView is DataBind is the particular event handler that triggered the page
    call in the first place.

    Now, as an aside... You do know that you can fill, bind, populate, select,
    sort, edit, and page a GridView without a single line of code, right?

    Good luck!

    -Scott


    "Hrvoje Vrbanc" <> wrote in message
    news:...
    > Thanks!
    > However, I have tried a "basic set up" and had the same problems.
    > I have inserted a GridView, changed nothing and added just two events in
    > the codebehind (beside the code necessary to create, fill and bind the
    > dataset):
    >
    > Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e
    > As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles
    > GridView1.RowCancelingEdit
    >
    > GridView1.EditIndex = -1
    >
    > End Sub
    >
    > Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As
    > System.Web.UI.WebControls.GridViewEditEventArgs) Handles
    > GridView1.RowEditing
    >
    > GridView1.EditIndex = e.NewEditIndex
    >
    > End Sub
    >
    >
    >
    > Maybe that's because there's no real code beside index determination?
    >
    >
    >
    > Thank you,
    >
    > Hrvoje
    >
    >
    >
    >
    >
    > "Scott M." <> wrote in message
    > news:...
    >> Have you written any custom code for your GridView? This behavior is
    >> usually associated with calling DataBind incorrectly and/or turning off
    >> ViewState for the control.
    >>
    >> Try another test, but this time don't change any properties of the
    >> GridView (not even its looks) and just enable Edit, Update, & Cancel via
    >> the smart tag. See if this works properly.
    >>
    >>
    >> "Hrvoje Vrbanc" <> wrote in message
    >> news:...
    >>> Hello all,
    >>>
    >>> I've encountered a very strange problem: I have a GridView control on an
    >>> .aspx page that displays data correctly (in any case; with autogenerated
    >>> columns or with using item templates).
    >>>
    >>> I added "Edit, Update, Cancel" command button to the GridView but when I
    >>> click on "Edit" nothing happens. I have to click the same button again
    >>> and only then the row displays EditItem template.
    >>>
    >>> The same happens when I press, e.g. "Cancel" button - it takes two
    >>> clicks to enter normal GridView display mode.
    >>>
    >>> I tried it on two machines and on both VS development server and full
    >>> IIS and it's always the same. It's very strange.
    >>>
    >>> Is it some sort of a trivial problem and I'm somehow missing something
    >>> obvious?
    >>>
    >>> Thank you in advance,
    >>> Hrvoje
    >>>

    >>

    >
    >
     
    Scott M., Nov 26, 2007
    #4
  5. Thank you!
    In fact, my DataGrid was populated on click of the button that executed a
    query corresponding to the search string.

    But, as soon as I added a call to the Binding() sub to those two evets,
    things started working prefectly.
    Thank you once more!

    Regards,
    Hrvoje



    "Scott M." <> wrote in message
    news:...
    > Yes, as suspected the problem is in your code, and is a DataBind call
    > problem.
    >
    > You didn't provide your complete code that fills and binds (and is part of
    > the problem), but I can explain what to do anyway.
    >
    > You only want to be calling the Databind method once per page call and it
    > must be done at the "right" time. I suspect your call is in your
    > Page_Load event and *not* wrapped in a test for a postback, as it should
    > be. Your filling and binding code should look something like this:
    >
    > Sub Page_Load()
    > 'code to connect and fill
    > If Not IsPostBack Then
    > 'Databinding should be the last thing you do to your GridView
    > 'Since we know this code only runs the first time your page is
    > being loaded,
    > 'we know that it's not being loaded as a result of any kind of
    > GridView user
    > 'manipulation (like a sort, select, edit, or page change)
    > GridView.DataBind
    > End If
    > End Sub
    >
    > When your page is loading for the first time, your event handlers for
    > selecting, sorting, editing and paging are not going to be called because
    > how could a user be doing such things if they haven't even received the
    > page for the first time?
    >
    > But, what if the page is loading NOT for the first time? Then, we have to
    > ask *why* would the page be loading for a subsequent time? The answer is
    > that the user initiated this subsequent page call by sorting, selecting,
    > editing, or paging the GridVeiw, in which case, Page_Load will NOT be the
    > last page event to fire in these cases. If you had been binding your
    > GridView in Page_Load for every page call (as I suspect you have been
    > doing), then you are binding your GridView before your code is done
    > working with it (sure Page_Load is done, but now we've got to execute the
    > sort, select, edit, paging event handlers).
    >
    > So, in PostBack situations, we don't want to bind to the GridView yet, we
    > want to do it when we are done configuring the GridView for this current
    > page display. This means that in EACH of your GridView event handlers,
    > the LAST command should be GridVeiw.DataBind(). For example:
    >
    > Sub GridView1_RowCancelingEdit(ByVal . . .) Handles
    > GridView1.RowCancelingEdit
    > GridView1.EditIndex = -1
    > GridView1.DataBind()
    > End Sub
    >
    > Sub GridView1_RowEditing(ByVal . . .) Handles GridView1.RowEditing
    > GridView1.EditIndex = e.NewEditIndex
    > GridView1.DataBind()
    > End Sub
    >
    > This way we know the following:
    > 1. The first time the page loads, the LAST thing done to the GridView
    > is DataBind in Page_Load
    > 2. Any subsequent time the page loads, the LAST thing done to the
    > GridView is DataBind is the particular event handler that triggered the
    > page call in the first place.
    >
    > Now, as an aside... You do know that you can fill, bind, populate, select,
    > sort, edit, and page a GridView without a single line of code, right?
    >
    > Good luck!
    >
    > -Scott
    >
    >
    > "Hrvoje Vrbanc" <> wrote in message
    > news:...
    >> Thanks!
    >> However, I have tried a "basic set up" and had the same problems.
    >> I have inserted a GridView, changed nothing and added just two events in
    >> the codebehind (beside the code necessary to create, fill and bind the
    >> dataset):
    >>
    >> Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e
    >> As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles
    >> GridView1.RowCancelingEdit
    >>
    >> GridView1.EditIndex = -1
    >>
    >> End Sub
    >>
    >> Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As
    >> System.Web.UI.WebControls.GridViewEditEventArgs) Handles
    >> GridView1.RowEditing
    >>
    >> GridView1.EditIndex = e.NewEditIndex
    >>
    >> End Sub
    >>
    >>
    >>
    >> Maybe that's because there's no real code beside index determination?
    >>
    >>
    >>
    >> Thank you,
    >>
    >> Hrvoje
    >>
    >>
    >>
    >>
    >>
    >> "Scott M." <> wrote in message
    >> news:...
    >>> Have you written any custom code for your GridView? This behavior is
    >>> usually associated with calling DataBind incorrectly and/or turning off
    >>> ViewState for the control.
    >>>
    >>> Try another test, but this time don't change any properties of the
    >>> GridView (not even its looks) and just enable Edit, Update, & Cancel via
    >>> the smart tag. See if this works properly.
    >>>
    >>>
    >>> "Hrvoje Vrbanc" <> wrote in message
    >>> news:...
    >>>> Hello all,
    >>>>
    >>>> I've encountered a very strange problem: I have a GridView control on
    >>>> an .aspx page that displays data correctly (in any case; with
    >>>> autogenerated columns or with using item templates).
    >>>>
    >>>> I added "Edit, Update, Cancel" command button to the GridView but when
    >>>> I click on "Edit" nothing happens. I have to click the same button
    >>>> again and only then the row displays EditItem template.
    >>>>
    >>>> The same happens when I press, e.g. "Cancel" button - it takes two
    >>>> clicks to enter normal GridView display mode.
    >>>>
    >>>> I tried it on two machines and on both VS development server and full
    >>>> IIS and it's always the same. It's very strange.
    >>>>
    >>>> Is it some sort of a trivial problem and I'm somehow missing something
    >>>> obvious?
    >>>>
    >>>> Thank you in advance,
    >>>> Hrvoje
    >>>>
    >>>

    >>
    >>

    >
     
    Hrvoje Vrbanc, Nov 26, 2007
    #5
  6. Hrvoje Vrbanc

    Scott M. Guest

    Glad to help. And, by the way, even though you are using the value from a
    control as a parameter to a query, you can still do all of this with no code
    in VS 2005. In the DataSet Wizard, you have the choice to make a
    parameterized query that gets its value from an existing control.

    Good luck!

    -Scott


    "Hrvoje Vrbanc" <> wrote in message
    news:...
    > Thank you!
    > In fact, my DataGrid was populated on click of the button that executed a
    > query corresponding to the search string.
    >
    > But, as soon as I added a call to the Binding() sub to those two evets,
    > things started working prefectly.
    > Thank you once more!
    >
    > Regards,
    > Hrvoje
    >
    >
    >
    > "Scott M." <> wrote in message
    > news:...
    >> Yes, as suspected the problem is in your code, and is a DataBind call
    >> problem.
    >>
    >> You didn't provide your complete code that fills and binds (and is part
    >> of the problem), but I can explain what to do anyway.
    >>
    >> You only want to be calling the Databind method once per page call and it
    >> must be done at the "right" time. I suspect your call is in your
    >> Page_Load event and *not* wrapped in a test for a postback, as it should
    >> be. Your filling and binding code should look something like this:
    >>
    >> Sub Page_Load()
    >> 'code to connect and fill
    >> If Not IsPostBack Then
    >> 'Databinding should be the last thing you do to your GridView
    >> 'Since we know this code only runs the first time your page is
    >> being loaded,
    >> 'we know that it's not being loaded as a result of any kind of
    >> GridView user
    >> 'manipulation (like a sort, select, edit, or page change)
    >> GridView.DataBind
    >> End If
    >> End Sub
    >>
    >> When your page is loading for the first time, your event handlers for
    >> selecting, sorting, editing and paging are not going to be called because
    >> how could a user be doing such things if they haven't even received the
    >> page for the first time?
    >>
    >> But, what if the page is loading NOT for the first time? Then, we have
    >> to ask *why* would the page be loading for a subsequent time? The answer
    >> is that the user initiated this subsequent page call by sorting,
    >> selecting, editing, or paging the GridVeiw, in which case, Page_Load will
    >> NOT be the last page event to fire in these cases. If you had been
    >> binding your GridView in Page_Load for every page call (as I suspect you
    >> have been doing), then you are binding your GridView before your code is
    >> done working with it (sure Page_Load is done, but now we've got to
    >> execute the sort, select, edit, paging event handlers).
    >>
    >> So, in PostBack situations, we don't want to bind to the GridView yet, we
    >> want to do it when we are done configuring the GridView for this current
    >> page display. This means that in EACH of your GridView event handlers,
    >> the LAST command should be GridVeiw.DataBind(). For example:
    >>
    >> Sub GridView1_RowCancelingEdit(ByVal . . .) Handles
    >> GridView1.RowCancelingEdit
    >> GridView1.EditIndex = -1
    >> GridView1.DataBind()
    >> End Sub
    >>
    >> Sub GridView1_RowEditing(ByVal . . .) Handles GridView1.RowEditing
    >> GridView1.EditIndex = e.NewEditIndex
    >> GridView1.DataBind()
    >> End Sub
    >>
    >> This way we know the following:
    >> 1. The first time the page loads, the LAST thing done to the GridView
    >> is DataBind in Page_Load
    >> 2. Any subsequent time the page loads, the LAST thing done to the
    >> GridView is DataBind is the particular event handler that triggered the
    >> page call in the first place.
    >>
    >> Now, as an aside... You do know that you can fill, bind, populate,
    >> select, sort, edit, and page a GridView without a single line of code,
    >> right?
    >>
    >> Good luck!
    >>
    >> -Scott
    >>
    >>
    >> "Hrvoje Vrbanc" <> wrote in message
    >> news:...
    >>> Thanks!
    >>> However, I have tried a "basic set up" and had the same problems.
    >>> I have inserted a GridView, changed nothing and added just two events in
    >>> the codebehind (beside the code necessary to create, fill and bind the
    >>> dataset):
    >>>
    >>> Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e
    >>> As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles
    >>> GridView1.RowCancelingEdit
    >>>
    >>> GridView1.EditIndex = -1
    >>>
    >>> End Sub
    >>>
    >>> Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As
    >>> System.Web.UI.WebControls.GridViewEditEventArgs) Handles
    >>> GridView1.RowEditing
    >>>
    >>> GridView1.EditIndex = e.NewEditIndex
    >>>
    >>> End Sub
    >>>
    >>>
    >>>
    >>> Maybe that's because there's no real code beside index determination?
    >>>
    >>>
    >>>
    >>> Thank you,
    >>>
    >>> Hrvoje
    >>>
    >>>
    >>>
    >>>
    >>>
    >>> "Scott M." <> wrote in message
    >>> news:...
    >>>> Have you written any custom code for your GridView? This behavior is
    >>>> usually associated with calling DataBind incorrectly and/or turning off
    >>>> ViewState for the control.
    >>>>
    >>>> Try another test, but this time don't change any properties of the
    >>>> GridView (not even its looks) and just enable Edit, Update, & Cancel
    >>>> via the smart tag. See if this works properly.
    >>>>
    >>>>
    >>>> "Hrvoje Vrbanc" <> wrote in message
    >>>> news:...
    >>>>> Hello all,
    >>>>>
    >>>>> I've encountered a very strange problem: I have a GridView control on
    >>>>> an .aspx page that displays data correctly (in any case; with
    >>>>> autogenerated columns or with using item templates).
    >>>>>
    >>>>> I added "Edit, Update, Cancel" command button to the GridView but when
    >>>>> I click on "Edit" nothing happens. I have to click the same button
    >>>>> again and only then the row displays EditItem template.
    >>>>>
    >>>>> The same happens when I press, e.g. "Cancel" button - it takes two
    >>>>> clicks to enter normal GridView display mode.
    >>>>>
    >>>>> I tried it on two machines and on both VS development server and full
    >>>>> IIS and it's always the same. It's very strange.
    >>>>>
    >>>>> Is it some sort of a trivial problem and I'm somehow missing something
    >>>>> obvious?
    >>>>>
    >>>>> Thank you in advance,
    >>>>> Hrvoje
    >>>>>
    >>>>
    >>>
    >>>

    >>

    >
    >
     
    Scott M., Nov 26, 2007
    #6
  7. Thank you very much.
    I never tried using wizards too much in ASP.NET 2.0 because I like to have
    as much as possible of my code in the codebehind (I don't like having e.g.
    SQL code in an .aspx file). Or, better said, I never got into wizard offered
    possibilities deep enough and continued to work as much as possible as in
    ASP.NET 1.1 (I've done the vast majority of my work in 1.1 because MS CMS
    2002 that I use for my sites requires 1.1).

    Also, I always tend to write as much code as possible in separate classes
    that I instantiate from the codebehind and almost always use stored
    procedures located on an SQL Server. In fact, I'm not familiar with what I
    gain if I do the things the different way.

    Hrvoje



    "Scott M." <> wrote in message
    news:...
    > Glad to help. And, by the way, even though you are using the value from a
    > control as a parameter to a query, you can still do all of this with no
    > code in VS 2005. In the DataSet Wizard, you have the choice to make a
    > parameterized query that gets its value from an existing control.
    >
    > Good luck!
    >
    > -Scott
    >
    >
    > "Hrvoje Vrbanc" <> wrote in message
    > news:...
    >> Thank you!
    >> In fact, my DataGrid was populated on click of the button that executed a
    >> query corresponding to the search string.
    >>
    >> But, as soon as I added a call to the Binding() sub to those two evets,
    >> things started working prefectly.
    >> Thank you once more!
    >>
    >> Regards,
    >> Hrvoje
    >>
    >>
    >>
    >> "Scott M." <> wrote in message
    >> news:...
    >>> Yes, as suspected the problem is in your code, and is a DataBind call
    >>> problem.
    >>>
    >>> You didn't provide your complete code that fills and binds (and is part
    >>> of the problem), but I can explain what to do anyway.
    >>>
    >>> You only want to be calling the Databind method once per page call and
    >>> it must be done at the "right" time. I suspect your call is in your
    >>> Page_Load event and *not* wrapped in a test for a postback, as it should
    >>> be. Your filling and binding code should look something like this:
    >>>
    >>> Sub Page_Load()
    >>> 'code to connect and fill
    >>> If Not IsPostBack Then
    >>> 'Databinding should be the last thing you do to your GridView
    >>> 'Since we know this code only runs the first time your page is
    >>> being loaded,
    >>> 'we know that it's not being loaded as a result of any kind of
    >>> GridView user
    >>> 'manipulation (like a sort, select, edit, or page change)
    >>> GridView.DataBind
    >>> End If
    >>> End Sub
    >>>
    >>> When your page is loading for the first time, your event handlers for
    >>> selecting, sorting, editing and paging are not going to be called
    >>> because how could a user be doing such things if they haven't even
    >>> received the page for the first time?
    >>>
    >>> But, what if the page is loading NOT for the first time? Then, we have
    >>> to ask *why* would the page be loading for a subsequent time? The
    >>> answer is that the user initiated this subsequent page call by sorting,
    >>> selecting, editing, or paging the GridVeiw, in which case, Page_Load
    >>> will NOT be the last page event to fire in these cases. If you had been
    >>> binding your GridView in Page_Load for every page call (as I suspect you
    >>> have been doing), then you are binding your GridView before your code is
    >>> done working with it (sure Page_Load is done, but now we've got to
    >>> execute the sort, select, edit, paging event handlers).
    >>>
    >>> So, in PostBack situations, we don't want to bind to the GridView yet,
    >>> we want to do it when we are done configuring the GridView for this
    >>> current page display. This means that in EACH of your GridView event
    >>> handlers, the LAST command should be GridVeiw.DataBind(). For example:
    >>>
    >>> Sub GridView1_RowCancelingEdit(ByVal . . .) Handles
    >>> GridView1.RowCancelingEdit
    >>> GridView1.EditIndex = -1
    >>> GridView1.DataBind()
    >>> End Sub
    >>>
    >>> Sub GridView1_RowEditing(ByVal . . .) Handles GridView1.RowEditing
    >>> GridView1.EditIndex = e.NewEditIndex
    >>> GridView1.DataBind()
    >>> End Sub
    >>>
    >>> This way we know the following:
    >>> 1. The first time the page loads, the LAST thing done to the
    >>> GridView is DataBind in Page_Load
    >>> 2. Any subsequent time the page loads, the LAST thing done to the
    >>> GridView is DataBind is the particular event handler that triggered the
    >>> page call in the first place.
    >>>
    >>> Now, as an aside... You do know that you can fill, bind, populate,
    >>> select, sort, edit, and page a GridView without a single line of code,
    >>> right?
    >>>
    >>> Good luck!
    >>>
    >>> -Scott
    >>>
    >>>
    >>> "Hrvoje Vrbanc" <> wrote in message
    >>> news:...
    >>>> Thanks!
    >>>> However, I have tried a "basic set up" and had the same problems.
    >>>> I have inserted a GridView, changed nothing and added just two events
    >>>> in the codebehind (beside the code necessary to create, fill and bind
    >>>> the dataset):
    >>>>
    >>>> Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal
    >>>> e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles
    >>>> GridView1.RowCancelingEdit
    >>>>
    >>>> GridView1.EditIndex = -1
    >>>>
    >>>> End Sub
    >>>>
    >>>> Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As
    >>>> System.Web.UI.WebControls.GridViewEditEventArgs) Handles
    >>>> GridView1.RowEditing
    >>>>
    >>>> GridView1.EditIndex = e.NewEditIndex
    >>>>
    >>>> End Sub
    >>>>
    >>>>
    >>>>
    >>>> Maybe that's because there's no real code beside index determination?
    >>>>
    >>>>
    >>>>
    >>>> Thank you,
    >>>>
    >>>> Hrvoje
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>
    >>>> "Scott M." <> wrote in message
    >>>> news:...
    >>>>> Have you written any custom code for your GridView? This behavior is
    >>>>> usually associated with calling DataBind incorrectly and/or turning
    >>>>> off ViewState for the control.
    >>>>>
    >>>>> Try another test, but this time don't change any properties of the
    >>>>> GridView (not even its looks) and just enable Edit, Update, & Cancel
    >>>>> via the smart tag. See if this works properly.
    >>>>>
    >>>>>
    >>>>> "Hrvoje Vrbanc" <> wrote in message
    >>>>> news:...
    >>>>>> Hello all,
    >>>>>>
    >>>>>> I've encountered a very strange problem: I have a GridView control on
    >>>>>> an .aspx page that displays data correctly (in any case; with
    >>>>>> autogenerated columns or with using item templates).
    >>>>>>
    >>>>>> I added "Edit, Update, Cancel" command button to the GridView but
    >>>>>> when I click on "Edit" nothing happens. I have to click the same
    >>>>>> button again and only then the row displays EditItem template.
    >>>>>>
    >>>>>> The same happens when I press, e.g. "Cancel" button - it takes two
    >>>>>> clicks to enter normal GridView display mode.
    >>>>>>
    >>>>>> I tried it on two machines and on both VS development server and full
    >>>>>> IIS and it's always the same. It's very strange.
    >>>>>>
    >>>>>> Is it some sort of a trivial problem and I'm somehow missing
    >>>>>> something obvious?
    >>>>>>
    >>>>>> Thank you in advance,
    >>>>>> Hrvoje
    >>>>>>
    >>>>>
    >>>>
    >>>>
    >>>

    >>
    >>

    >
     
    Hrvoje Vrbanc, Nov 26, 2007
    #7
  8. Hrvoje Vrbanc

    Scott M. Guest

    Hi Hrvoje

    See my comments inline.....

    "Hrvoje Vrbanc" <> wrote in message
    news:...
    > Thank you very much.
    > I never tried using wizards too much in ASP.NET 2.0 because I like to have
    > as much as possible of my code in the codebehind (I don't like having e.g.
    > SQL code in an .aspx file).


    Because of the new declarative way that ASP .NET 2.0 controls
    compile/render, there's much less actual code to even worry about now.

    > Or, better said, I never got into wizard offered possibilities deep enough
    > and continued to work as much as possible as in ASP.NET 1.1 (I've done the
    > vast majority of my work in 1.1 because MS CMS 2002 that I use for my
    > sites requires 1.1).
    >
    > Also, I always tend to write as much code as possible in separate classes
    > that I instantiate from the codebehind and almost always use stored
    > procedures located on an SQL Server. In fact, I'm not familiar with what I
    > gain if I do the things the different way.


    In ASP .NET 2.0 the controls can be configured to use stored procedures
    (with parameters based on controls, querystrings, etc.) without any vb code
    at design-time (zero code in the code-behind). What you gain is not having
    to worry about coding Databinding, Editing, Updating, Sorting, Deleting and
    Paging! :)

    -Scott

    >
    > Hrvoje
    >
    >
    >
    > "Scott M." <> wrote in message
    > news:...
    >> Glad to help. And, by the way, even though you are using the value from
    >> a control as a parameter to a query, you can still do all of this with no
    >> code in VS 2005. In the DataSet Wizard, you have the choice to make a
    >> parameterized query that gets its value from an existing control.
    >>
    >> Good luck!
    >>
    >> -Scott
    >>
    >>
    >> "Hrvoje Vrbanc" <> wrote in message
    >> news:...
    >>> Thank you!
    >>> In fact, my DataGrid was populated on click of the button that executed
    >>> a query corresponding to the search string.
    >>>
    >>> But, as soon as I added a call to the Binding() sub to those two evets,
    >>> things started working prefectly.
    >>> Thank you once more!
    >>>
    >>> Regards,
    >>> Hrvoje
    >>>
    >>>
    >>>
    >>> "Scott M." <> wrote in message
    >>> news:...
    >>>> Yes, as suspected the problem is in your code, and is a DataBind call
    >>>> problem.
    >>>>
    >>>> You didn't provide your complete code that fills and binds (and is part
    >>>> of the problem), but I can explain what to do anyway.
    >>>>
    >>>> You only want to be calling the Databind method once per page call and
    >>>> it must be done at the "right" time. I suspect your call is in your
    >>>> Page_Load event and *not* wrapped in a test for a postback, as it
    >>>> should be. Your filling and binding code should look something like
    >>>> this:
    >>>>
    >>>> Sub Page_Load()
    >>>> 'code to connect and fill
    >>>> If Not IsPostBack Then
    >>>> 'Databinding should be the last thing you do to your GridView
    >>>> 'Since we know this code only runs the first time your page is
    >>>> being loaded,
    >>>> 'we know that it's not being loaded as a result of any kind of
    >>>> GridView user
    >>>> 'manipulation (like a sort, select, edit, or page change)
    >>>> GridView.DataBind
    >>>> End If
    >>>> End Sub
    >>>>
    >>>> When your page is loading for the first time, your event handlers for
    >>>> selecting, sorting, editing and paging are not going to be called
    >>>> because how could a user be doing such things if they haven't even
    >>>> received the page for the first time?
    >>>>
    >>>> But, what if the page is loading NOT for the first time? Then, we have
    >>>> to ask *why* would the page be loading for a subsequent time? The
    >>>> answer is that the user initiated this subsequent page call by sorting,
    >>>> selecting, editing, or paging the GridVeiw, in which case, Page_Load
    >>>> will NOT be the last page event to fire in these cases. If you had
    >>>> been binding your GridView in Page_Load for every page call (as I
    >>>> suspect you have been doing), then you are binding your GridView before
    >>>> your code is done working with it (sure Page_Load is done, but now
    >>>> we've got to execute the sort, select, edit, paging event handlers).
    >>>>
    >>>> So, in PostBack situations, we don't want to bind to the GridView yet,
    >>>> we want to do it when we are done configuring the GridView for this
    >>>> current page display. This means that in EACH of your GridView event
    >>>> handlers, the LAST command should be GridVeiw.DataBind(). For example:
    >>>>
    >>>> Sub GridView1_RowCancelingEdit(ByVal . . .) Handles
    >>>> GridView1.RowCancelingEdit
    >>>> GridView1.EditIndex = -1
    >>>> GridView1.DataBind()
    >>>> End Sub
    >>>>
    >>>> Sub GridView1_RowEditing(ByVal . . .) Handles GridView1.RowEditing
    >>>> GridView1.EditIndex = e.NewEditIndex
    >>>> GridView1.DataBind()
    >>>> End Sub
    >>>>
    >>>> This way we know the following:
    >>>> 1. The first time the page loads, the LAST thing done to the
    >>>> GridView is DataBind in Page_Load
    >>>> 2. Any subsequent time the page loads, the LAST thing done to the
    >>>> GridView is DataBind is the particular event handler that triggered the
    >>>> page call in the first place.
    >>>>
    >>>> Now, as an aside... You do know that you can fill, bind, populate,
    >>>> select, sort, edit, and page a GridView without a single line of code,
    >>>> right?
    >>>>
    >>>> Good luck!
    >>>>
    >>>> -Scott
    >>>>
    >>>>
    >>>> "Hrvoje Vrbanc" <> wrote in message
    >>>> news:...
    >>>>> Thanks!
    >>>>> However, I have tried a "basic set up" and had the same problems.
    >>>>> I have inserted a GridView, changed nothing and added just two events
    >>>>> in the codebehind (beside the code necessary to create, fill and bind
    >>>>> the dataset):
    >>>>>
    >>>>> Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal
    >>>>> e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles
    >>>>> GridView1.RowCancelingEdit
    >>>>>
    >>>>> GridView1.EditIndex = -1
    >>>>>
    >>>>> End Sub
    >>>>>
    >>>>> Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As
    >>>>> System.Web.UI.WebControls.GridViewEditEventArgs) Handles
    >>>>> GridView1.RowEditing
    >>>>>
    >>>>> GridView1.EditIndex = e.NewEditIndex
    >>>>>
    >>>>> End Sub
    >>>>>
    >>>>>
    >>>>>
    >>>>> Maybe that's because there's no real code beside index determination?
    >>>>>
    >>>>>
    >>>>>
    >>>>> Thank you,
    >>>>>
    >>>>> Hrvoje
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>>
    >>>>> "Scott M." <> wrote in message
    >>>>> news:...
    >>>>>> Have you written any custom code for your GridView? This behavior is
    >>>>>> usually associated with calling DataBind incorrectly and/or turning
    >>>>>> off ViewState for the control.
    >>>>>>
    >>>>>> Try another test, but this time don't change any properties of the
    >>>>>> GridView (not even its looks) and just enable Edit, Update, & Cancel
    >>>>>> via the smart tag. See if this works properly.
    >>>>>>
    >>>>>>
    >>>>>> "Hrvoje Vrbanc" <> wrote in message
    >>>>>> news:...
    >>>>>>> Hello all,
    >>>>>>>
    >>>>>>> I've encountered a very strange problem: I have a GridView control
    >>>>>>> on an .aspx page that displays data correctly (in any case; with
    >>>>>>> autogenerated columns or with using item templates).
    >>>>>>>
    >>>>>>> I added "Edit, Update, Cancel" command button to the GridView but
    >>>>>>> when I click on "Edit" nothing happens. I have to click the same
    >>>>>>> button again and only then the row displays EditItem template.
    >>>>>>>
    >>>>>>> The same happens when I press, e.g. "Cancel" button - it takes two
    >>>>>>> clicks to enter normal GridView display mode.
    >>>>>>>
    >>>>>>> I tried it on two machines and on both VS development server and
    >>>>>>> full IIS and it's always the same. It's very strange.
    >>>>>>>
    >>>>>>> Is it some sort of a trivial problem and I'm somehow missing
    >>>>>>> something obvious?
    >>>>>>>
    >>>>>>> Thank you in advance,
    >>>>>>> Hrvoje
    >>>>>>>
    >>>>>>
    >>>>>
    >>>>>
    >>>>
    >>>
    >>>

    >>

    >
    >
     
    Scott M., Nov 27, 2007
    #8
  9. Thank you very much, Scott, you've been a great help!
    Hrvoje




    "Scott M." <> wrote in message
    news:D...
    > Hi Hrvoje
    >
    > See my comments inline.....
    >
    > "Hrvoje Vrbanc" <> wrote in message
    > news:...
    >> Thank you very much.
    >> I never tried using wizards too much in ASP.NET 2.0 because I like to
    >> have as much as possible of my code in the codebehind (I don't like
    >> having e.g. SQL code in an .aspx file).

    >
    > Because of the new declarative way that ASP .NET 2.0 controls
    > compile/render, there's much less actual code to even worry about now.
    >
    >> Or, better said, I never got into wizard offered possibilities deep
    >> enough and continued to work as much as possible as in ASP.NET 1.1 (I've
    >> done the vast majority of my work in 1.1 because MS CMS 2002 that I use
    >> for my sites requires 1.1).
    >>
    >> Also, I always tend to write as much code as possible in separate classes
    >> that I instantiate from the codebehind and almost always use stored
    >> procedures located on an SQL Server. In fact, I'm not familiar with what
    >> I gain if I do the things the different way.

    >
    > In ASP .NET 2.0 the controls can be configured to use stored procedures
    > (with parameters based on controls, querystrings, etc.) without any vb
    > code at design-time (zero code in the code-behind). What you gain is not
    > having to worry about coding Databinding, Editing, Updating, Sorting,
    > Deleting and Paging! :)
    >
    > -Scott
    >
    >>
    >> Hrvoje
    >>
    >>
    >>
    >> "Scott M." <> wrote in message
    >> news:...
    >>> Glad to help. And, by the way, even though you are using the value from
    >>> a control as a parameter to a query, you can still do all of this with
    >>> no code in VS 2005. In the DataSet Wizard, you have the choice to make
    >>> a parameterized query that gets its value from an existing control.
    >>>
    >>> Good luck!
    >>>
    >>> -Scott
    >>>
    >>>
    >>> "Hrvoje Vrbanc" <> wrote in message
    >>> news:...
    >>>> Thank you!
    >>>> In fact, my DataGrid was populated on click of the button that executed
    >>>> a query corresponding to the search string.
    >>>>
    >>>> But, as soon as I added a call to the Binding() sub to those two evets,
    >>>> things started working prefectly.
    >>>> Thank you once more!
    >>>>
    >>>> Regards,
    >>>> Hrvoje
    >>>>
    >>>>
    >>>>
    >>>> "Scott M." <> wrote in message
    >>>> news:...
    >>>>> Yes, as suspected the problem is in your code, and is a DataBind call
    >>>>> problem.
    >>>>>
    >>>>> You didn't provide your complete code that fills and binds (and is
    >>>>> part of the problem), but I can explain what to do anyway.
    >>>>>
    >>>>> You only want to be calling the Databind method once per page call and
    >>>>> it must be done at the "right" time. I suspect your call is in your
    >>>>> Page_Load event and *not* wrapped in a test for a postback, as it
    >>>>> should be. Your filling and binding code should look something like
    >>>>> this:
    >>>>>
    >>>>> Sub Page_Load()
    >>>>> 'code to connect and fill
    >>>>> If Not IsPostBack Then
    >>>>> 'Databinding should be the last thing you do to your GridView
    >>>>> 'Since we know this code only runs the first time your page is
    >>>>> being loaded,
    >>>>> 'we know that it's not being loaded as a result of any kind of
    >>>>> GridView user
    >>>>> 'manipulation (like a sort, select, edit, or page change)
    >>>>> GridView.DataBind
    >>>>> End If
    >>>>> End Sub
    >>>>>
    >>>>> When your page is loading for the first time, your event handlers for
    >>>>> selecting, sorting, editing and paging are not going to be called
    >>>>> because how could a user be doing such things if they haven't even
    >>>>> received the page for the first time?
    >>>>>
    >>>>> But, what if the page is loading NOT for the first time? Then, we
    >>>>> have to ask *why* would the page be loading for a subsequent time?
    >>>>> The answer is that the user initiated this subsequent page call by
    >>>>> sorting, selecting, editing, or paging the GridVeiw, in which case,
    >>>>> Page_Load will NOT be the last page event to fire in these cases. If
    >>>>> you had been binding your GridView in Page_Load for every page call
    >>>>> (as I suspect you have been doing), then you are binding your GridView
    >>>>> before your code is done working with it (sure Page_Load is done, but
    >>>>> now we've got to execute the sort, select, edit, paging event
    >>>>> handlers).
    >>>>>
    >>>>> So, in PostBack situations, we don't want to bind to the GridView yet,
    >>>>> we want to do it when we are done configuring the GridView for this
    >>>>> current page display. This means that in EACH of your GridView event
    >>>>> handlers, the LAST command should be GridVeiw.DataBind(). For
    >>>>> example:
    >>>>>
    >>>>> Sub GridView1_RowCancelingEdit(ByVal . . .) Handles
    >>>>> GridView1.RowCancelingEdit
    >>>>> GridView1.EditIndex = -1
    >>>>> GridView1.DataBind()
    >>>>> End Sub
    >>>>>
    >>>>> Sub GridView1_RowEditing(ByVal . . .) Handles GridView1.RowEditing
    >>>>> GridView1.EditIndex = e.NewEditIndex
    >>>>> GridView1.DataBind()
    >>>>> End Sub
    >>>>>
    >>>>> This way we know the following:
    >>>>> 1. The first time the page loads, the LAST thing done to the
    >>>>> GridView is DataBind in Page_Load
    >>>>> 2. Any subsequent time the page loads, the LAST thing done to the
    >>>>> GridView is DataBind is the particular event handler that triggered
    >>>>> the page call in the first place.
    >>>>>
    >>>>> Now, as an aside... You do know that you can fill, bind, populate,
    >>>>> select, sort, edit, and page a GridView without a single line of code,
    >>>>> right?
    >>>>>
    >>>>> Good luck!
    >>>>>
    >>>>> -Scott
    >>>>>
    >>>>>
    >>>>> "Hrvoje Vrbanc" <> wrote in message
    >>>>> news:...
    >>>>>> Thanks!
    >>>>>> However, I have tried a "basic set up" and had the same problems.
    >>>>>> I have inserted a GridView, changed nothing and added just two events
    >>>>>> in the codebehind (beside the code necessary to create, fill and bind
    >>>>>> the dataset):
    >>>>>>
    >>>>>> Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object,
    >>>>>> ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs)
    >>>>>> Handles GridView1.RowCancelingEdit
    >>>>>>
    >>>>>> GridView1.EditIndex = -1
    >>>>>>
    >>>>>> End Sub
    >>>>>>
    >>>>>> Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As
    >>>>>> System.Web.UI.WebControls.GridViewEditEventArgs) Handles
    >>>>>> GridView1.RowEditing
    >>>>>>
    >>>>>> GridView1.EditIndex = e.NewEditIndex
    >>>>>>
    >>>>>> End Sub
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>> Maybe that's because there's no real code beside index determination?
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>> Thank you,
    >>>>>>
    >>>>>> Hrvoje
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>>
    >>>>>> "Scott M." <> wrote in message
    >>>>>> news:...
    >>>>>>> Have you written any custom code for your GridView? This behavior
    >>>>>>> is usually associated with calling DataBind incorrectly and/or
    >>>>>>> turning off ViewState for the control.
    >>>>>>>
    >>>>>>> Try another test, but this time don't change any properties of the
    >>>>>>> GridView (not even its looks) and just enable Edit, Update, & Cancel
    >>>>>>> via the smart tag. See if this works properly.
    >>>>>>>
    >>>>>>>
    >>>>>>> "Hrvoje Vrbanc" <> wrote in message
    >>>>>>> news:...
    >>>>>>>> Hello all,
    >>>>>>>>
    >>>>>>>> I've encountered a very strange problem: I have a GridView control
    >>>>>>>> on an .aspx page that displays data correctly (in any case; with
    >>>>>>>> autogenerated columns or with using item templates).
    >>>>>>>>
    >>>>>>>> I added "Edit, Update, Cancel" command button to the GridView but
    >>>>>>>> when I click on "Edit" nothing happens. I have to click the same
    >>>>>>>> button again and only then the row displays EditItem template.
    >>>>>>>>
    >>>>>>>> The same happens when I press, e.g. "Cancel" button - it takes two
    >>>>>>>> clicks to enter normal GridView display mode.
    >>>>>>>>
    >>>>>>>> I tried it on two machines and on both VS development server and
    >>>>>>>> full IIS and it's always the same. It's very strange.
    >>>>>>>>
    >>>>>>>> Is it some sort of a trivial problem and I'm somehow missing
    >>>>>>>> something obvious?
    >>>>>>>>
    >>>>>>>> Thank you in advance,
    >>>>>>>> Hrvoje
    >>>>>>>>
    >>>>>>>
    >>>>>>
    >>>>>>
    >>>>>
    >>>>
    >>>>
    >>>

    >>
    >>

    >
     
    Hrvoje Vrbanc, Nov 27, 2007
    #9
  10. GridView editing problem

    Hi, I was wondering if you could help me, I have a gridview that i populated using the wizzard, it displays the first,last name and contact number of people in the person table within the database. it allows for edit, update, cancel. then i have a search facility on first or lastname that takes the name entered in the textbox and calls stored procedures in the database depending on the selected index of the dropdown(Search by: containing first, last name). If you haven't searched for anything the edit update works perfectly, as soon as the grid gets populated with the search result and i click edit, the grid disappears. Can you tell me what the problem is? I have tried puting the gridview.databind() in all places possible but it just dont seem to want to work. any advice will be deeply appresiated...
     
    Ronelle Griffiths, Sep 16, 2008
    #10
    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. Ramsi

    Design Q - Avoiding two clicks

    Ramsi, Aug 21, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    462
    John Hann
    Aug 23, 2004
  2. John Famiglietti

    DataList ItemCommand Needs two clicks

    John Famiglietti, Dec 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    2,607
    John Famiglietti
    Dec 28, 2004
  3. Stuart Whiteford
    Replies:
    0
    Views:
    521
    Stuart Whiteford
    Jan 9, 2006
  4. PontiMax

    Clicks and double-clicks

    PontiMax, Jul 14, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    186
    Eliyahu Goldin
    Jul 14, 2004
  5. HopfZ
    Replies:
    0
    Views:
    576
    HopfZ
    Aug 28, 2006
Loading...

Share This Page