RowCancelingEdit and RowEditing take two mouse-clicks to work?

Discussion in 'ASP .Net Datagrid Control' started by dev648237923, Nov 15, 2006.

  1. dev648237923

    dev648237923 Guest

    I have a simple GridView. I need to do the Select and Edit in the code
    behind because I have to change schema prefix in the sql statement depending
    on the current user.

    I have the data grid and I have event handlers for edit and cancel but an
    odd thing happes: I have to click the Edit link twice for it to work and I
    need to click the Cancel link twice for it to work (the first postback does
    call my funcs but does not have any effect on how the grid looks -- I have
    to click the second time to get Update, Cancel to showup on the grid?). Is
    the below the correct way to do this? Thank you!

    <asp:gridview id="gv1" runat="server"
    AutoGenerateColumns="False"
    OnRowEditing="gv1_RowEditing"
    OnRowCancelingEdit="gv1_RowCancelingEdit">
    <Columns>
    <asp:CommandField ShowEditButton="True" />
    <asp:BoundField DataField="id" ReadOnly="True" />
    ...more bound fields go here
    </Columns>
    </asp:gridview>

    protected void gv1_RowEditing(object sender, GridViewEditEventArgs e)
    {
    gv1.EditIndex = e.NewEditIndex;
    //then call my sql to do the edit
    }
    protected void gv1_RowCancelingEdit(object sender,
    GridViewCancelEditEventArgs e)
    {
    gv1.EditIndex = -1;
    }

    p.s. I know it would be easier/better to design the db around this (have a
    usp and pass what schema to use, etc. but I am stuck with it this way so
    must do this on the asp.net side
     
    dev648237923, Nov 15, 2006
    #1
    1. Advertising

  2. Hello dev648237923,

    From your description, you're gettnig some strange behavior(need two time
    to make Gridview change status) when using GridView to display and edit
    data from database, correct?

    As for the GridView databinding, are you using an associated DataSource
    control(SqlDataSource or ObjectDataSource) or manually set the DataSource
    property and call DataBind method ?

    For Gridview, if you're using associated DataSource control to populate
    data, it will automatically handle the selecting, editing and updating
    events. However, if you manually bind the data, you need to manually hook
    those events (like RowEditing, RowUpdating, RowCancelingEdit ...) in code.
    Also, in each of such event, since you manually bind data to the GridView,
    you also need to do the databinding in each of those event because after
    each of such event, GridView need to repopulate the Rows collection. e.g.

    ========================
    .....................
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
    GridView1.EditIndex = e.NewEditIndex;
    GridView1.DataSource =
    SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    GridView1.DataBind();
    }

    protected void GridView1_RowCancelingEdit(object sender,
    GridViewCancelEditEventArgs e)
    {
    GridView1.EditIndex = -1;

    GridView1.DataSource =
    SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    GridView1.DataBind();
    }

    ...............
    ===========================

    If you feel necessary I can send you a test page for reference. Please feel
    free to let me know if you have any further questions or any thing
    particular in your scenario.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================



    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Nov 16, 2006
    #2
    1. Advertising

  3. dev648237923

    dev648237923 Guest

    Thank you for your ideas -- they fixed the problem which was I was not
    calling GridView1.DataBind() in th event handlers.
    Thank you!

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hello dev648237923,
    >
    > From your description, you're gettnig some strange behavior(need two time
    > to make Gridview change status) when using GridView to display and edit
    > data from database, correct?
    >
    > As for the GridView databinding, are you using an associated DataSource
    > control(SqlDataSource or ObjectDataSource) or manually set the DataSource
    > property and call DataBind method ?
    >
    > For Gridview, if you're using associated DataSource control to populate
    > data, it will automatically handle the selecting, editing and updating
    > events. However, if you manually bind the data, you need to manually hook
    > those events (like RowEditing, RowUpdating, RowCancelingEdit ...) in code.
    > Also, in each of such event, since you manually bind data to the GridView,
    > you also need to do the databinding in each of those event because after
    > each of such event, GridView need to repopulate the Rows collection. e.g.
    >
    > ========================
    > ....................
    > protected void GridView1_RowEditing(object sender, GridViewEditEventArgs
    > e)
    > {
    > GridView1.EditIndex = e.NewEditIndex;
    > GridView1.DataSource =
    > SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    > GridView1.DataBind();
    > }
    >
    > protected void GridView1_RowCancelingEdit(object sender,
    > GridViewCancelEditEventArgs e)
    > {
    > GridView1.EditIndex = -1;
    >
    > GridView1.DataSource =
    > SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    > GridView1.DataBind();
    > }
    >
    > ..............
    > ===========================
    >
    > If you feel necessary I can send you a test page for reference. Please
    > feel
    > free to let me know if you have any further questions or any thing
    > particular in your scenario.
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    >
    > ==================================================
    >
    > Get notification to my posts through email? Please refer to
    > http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    > ications.
    >
    >
    >
    > Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    > where an initial response from the community or a Microsoft Support
    > Engineer within 1 business day is acceptable. Please note that each follow
    > up response may take approximately 2 business days as the support
    > professional working with you may need further investigation to reach the
    > most efficient resolution. The offering is not appropriate for situations
    > that require urgent, real-time or phone-based interactions or complex
    > project analysis and dump analysis issues. Issues of this nature are best
    > handled working with a dedicated Microsoft Support Engineer by contacting
    > Microsoft Customer Support Services (CSS) at
    > http://msdn.microsoft.com/subscriptions/support/default.aspx.
    >
    > ==================================================
    >
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
     
    dev648237923, Nov 16, 2006
    #3
  4. That's great!

    Have a good day!

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Nov 17, 2006
    #4
    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. Pedro Sebastiao

    Simulating mouse clicks

    Pedro Sebastiao, May 24, 2004, in forum: C++
    Replies:
    2
    Views:
    1,754
    Prateek R Karandikar
    May 26, 2004
  2. John Fouhy
    Replies:
    2
    Views:
    618
    John Fouhy
    Jun 25, 2004
  3. Replies:
    17
    Views:
    1,366
  4. Replies:
    1
    Views:
    427
    Steve Holden
    Sep 5, 2005
  5. PontiMax

    Clicks and double-clicks

    PontiMax, Jul 14, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    192
    Eliyahu Goldin
    Jul 14, 2004
Loading...

Share This Page