Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > RowCancelingEdit and RowEditing take two mouse-clicks to work?

Reply
Thread Tools

RowCancelingEdit and RowEditing take two mouse-clicks to work?

 
 
dev648237923
Guest
Posts: n/a
 
      11-15-2006
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


 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      11-16-2006
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.Em pty);
GridView1.DataBind();
}

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

GridView1.DataSource =
SqlDataSource1.Select(DataSourceSelectArguments.Em pty);
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/subscripti...ult.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/subscripti...t/default.aspx.

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



This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
 
dev648237923
Guest
Posts: n/a
 
      11-16-2006
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.Em pty);
> GridView1.DataBind();
> }
>
> protected void GridView1_RowCancelingEdit(object sender,
> GridViewCancelEditEventArgs e)
> {
> GridView1.EditIndex = -1;
>
> GridView1.DataSource =
> SqlDataSource1.Select(DataSourceSelectArguments.Em pty);
> 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/subscripti...ult.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/subscripti...t/default.aspx.
>
> ==================================================
>
>
>
> This posting is provided "AS IS" with no warranties, and confers no
> rights.
>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      11-17-2006
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RowCommand vs RowEditing bladethinker@gmail.com ASP .Net 0 02-11-2009 01:43 AM
The GridView 'GridView2' fired event RowEditing which wasn't handl egsdar ASP .Net 0 11-04-2008 04:51 PM
Unable to retrieve contents on RowEditing (to cancel editing) Radu ASP .Net 2 02-01-2008 08:05 PM
Unable to retrieve contents on RowEditing (to cancel editing) Radu ASP .Net 0 02-01-2008 04:59 PM
Gridview RowEditing event problem =?Utf-8?B?V2lsbCBXaW5u?= ASP .Net 2 04-25-2006 09:12 PM



Advertisments