GridView -enable editing : DOTNET

This is a discussion on GridView -enable editing within the DOTNET forums in Framework and Interface Programming category; How do you enable editing in a GridView programatically rather than via its Tasks menu? Guy...

Go Back   ObjectMix Forum > Framework and Interface Programming > DOTNET

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 10-30-2007, 03:37 AM
=?Utf-8?B?Z3V5?=
Guest
 
Default GridView -enable editing

How do you enable editing in a GridView programatically rather than via its
Tasks menu?

Guy
Reply With Quote
  #2  
Old 10-30-2007, 04:51 AM
Michael Nemtsev, MVP
Guest
 
Default Re: GridView -enable editing

Hello guy,

try to set the AutoGenerateEditButton = true;

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


g> How do you enable editing in a GridView programatically rather than
g> via its Tasks menu?
g>
g> Guy
g>


Reply With Quote
  #3  
Old 10-30-2007, 05:07 AM
=?Utf-8?B?Z3V5?=
Guest
 
Default Re: GridView -enable editing

Michael,
AutoGenerateEditButton is already true,
and ithe edit button appears, What do I need to do in the RowEditing event
to actually edit the data?

Guy

"Michael Nemtsev" <Michael Nemtsev>, "MVP" wrote:

> Hello guy,
>
> try to set the AutoGenerateEditButton = true;
>
> ---
> WBR,
> Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
>
> "The greatest danger for most of us is not that our aim is too high and we
> miss it, but that it is too low and we reach it" (c) Michelangelo
>
>
> g> How do you enable editing in a GridView programatically rather than
> g> via its Tasks menu?
> g>
> g> Guy
> g>
>
>
>

Reply With Quote
  #4  
Old 10-30-2007, 05:10 AM
Michael Nemtsev, MVP
Guest
 
Default Re: GridView -enable editing

Hello guy,

then use GridView.EditIndex setting the row to edit

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


g> Michael,
g> AutoGenerateEditButton is already true,
g> and ithe edit button appears, What do I need to do in the RowEditing
g> event
g> to actually edit the data?
g> Guy
g>
g> "Michael Nemtsev" <Michael Nemtsev>, "MVP" wrote:
g>
>> Hello guy,
>>
>> try to set the AutoGenerateEditButton = true;
>>
>> ---
>> WBR,
>> Michael Nemtsev [.NET/C# MVP] :: blog:
>> http://spaces.live.com/laflour
>> "The greatest danger for most of us is not that our aim is too high
>> and we miss it, but that it is too low and we reach it" (c)
>> Michelangelo
>>
>> g> How do you enable editing in a GridView programatically rather
>> than
>> g> via its Tasks menu?
>> g>
>> g> Guy
>> g>



Reply With Quote
  #5  
Old 10-30-2007, 05:26 AM
Eliyahu Goldin
Guest
 
Default Re: GridView -enable editing

You need to handle 3 events. Here is an example for editing a grid with user
info. Note using EditIndex property.

protected void dgUsers_RowEditing(object sender, GridViewEditEventArgs e)

{

System.Web.UI.WebControls.GridView grid = sender as
System.Web.UI.WebControls.GridView;

grid.EditIndex = e.NewEditIndex;

grid.DataSource = System.Web.Security.Membership.GetAllUsers();

grid.DataBind();

}

protected void dgUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)

{

System.Web.UI.WebControls.GridView grid = sender as
System.Web.UI.WebControls.GridView;

System.Web.Security.MembershipUser userToUpdate =
System.Web.Security.Membership.GetUser(dgUsers.Dat aKeys[e.RowIndex].Value.ToString());

userToUpdate.Email = (dgUsers.Rows[e.RowIndex].Cells[5].Controls[0] as
System.Web.UI.WebControls.TextBox).Text;

System.Web.Security.Membership.UpdateUser(userToUp date);

bool isAdministrator =
(dgUsers.Rows[e.RowIndex].Cells[4].FindControl("chbAdministrator") as
System.Web.UI.WebControls.CheckBox).Checked;

if (isAdministrator)

System.Web.Security.Roles.AddUserToRole (userToUpdate.UserName, "Admin");

else

System.Web.Security.Roles.RemoveUserFromRole(userT oUpdate.UserName,
"rAdmin");

grid.EditIndex = -1;

grid.DataSource = System.Web.Security.Membership.GetAllUsers();

grid.DataBind();

}


protected void dgUsers_RowCancelingEdit(object sender,
GridViewCancelEditEventArgs e)

{

System.Web.UI.WebControls.GridView grid = sender as
System.Web.UI.WebControls.GridView;

grid.EditIndex = -1;

grid.DataSource = System.Web.Security.Membership.GetAllUsers();

grid.DataBind();

}



--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"guy" <guy@discussions.microsoft.com> wrote in message
news:5CFC33E7-CEBA-44C2-9A53-4C6C244E74EE@microsoft.com...
> Michael,
> AutoGenerateEditButton is already true,
> and ithe edit button appears, What do I need to do in the RowEditing event
> to actually edit the data?
>
> Guy
>
> "Michael Nemtsev" <Michael Nemtsev>, "MVP" wrote:
>
>> Hello guy,
>>
>> try to set the AutoGenerateEditButton = true;
>>
>> ---
>> WBR,
>> Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
>>
>> "The greatest danger for most of us is not that our aim is too high and
>> we
>> miss it, but that it is too low and we reach it" (c) Michelangelo
>>
>>
>> g> How do you enable editing in a GridView programatically rather than
>> g> via its Tasks menu?
>> g>
>> g> Guy
>> g>
>>
>>
>>



Reply With Quote
  #6  
Old 10-30-2007, 05:47 AM
=?Utf-8?B?Z3V5?=
Guest
 
Default Re: GridView -enable editing

Thanks Guys,
it was the resetting of the DataSource and re-binding that I was missing

cheers

Guy

"Eliyahu Goldin" wrote:

> You need to handle 3 events. Here is an example for editing a grid with user
> info. Note using EditIndex property.
>
> protected void dgUsers_RowEditing(object sender, GridViewEditEventArgs e)
>
> {
>
> System.Web.UI.WebControls.GridView grid = sender as
> System.Web.UI.WebControls.GridView;
>
> grid.EditIndex = e.NewEditIndex;
>
> grid.DataSource = System.Web.Security.Membership.GetAllUsers();
>
> grid.DataBind();
>
> }
>
> protected void dgUsers_RowUpdating(object sender, GridViewUpdateEventArgs e)
>
> {
>
> System.Web.UI.WebControls.GridView grid = sender as
> System.Web.UI.WebControls.GridView;
>
> System.Web.Security.MembershipUser userToUpdate =
> System.Web.Security.Membership.GetUser(dgUsers.Dat aKeys[e.RowIndex].Value.ToString());
>
> userToUpdate.Email = (dgUsers.Rows[e.RowIndex].Cells[5].Controls[0] as
> System.Web.UI.WebControls.TextBox).Text;
>
> System.Web.Security.Membership.UpdateUser(userToUp date);
>
> bool isAdministrator =
> (dgUsers.Rows[e.RowIndex].Cells[4].FindControl("chbAdministrator") as
> System.Web.UI.WebControls.CheckBox).Checked;
>
> if (isAdministrator)
>
> System.Web.Security.Roles.AddUserToRole (userToUpdate.UserName, "Admin");
>
> else
>
> System.Web.Security.Roles.RemoveUserFromRole(userT oUpdate.UserName,
> "rAdmin");
>
> grid.EditIndex = -1;
>
> grid.DataSource = System.Web.Security.Membership.GetAllUsers();
>
> grid.DataBind();
>
> }
>
>
> protected void dgUsers_RowCancelingEdit(object sender,
> GridViewCancelEditEventArgs e)
>
> {
>
> System.Web.UI.WebControls.GridView grid = sender as
> System.Web.UI.WebControls.GridView;
>
> grid.EditIndex = -1;
>
> grid.DataSource = System.Web.Security.Membership.GetAllUsers();
>
> grid.DataBind();
>
> }
>
>
>
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]
> http://msmvps.com/blogs/egoldin
> http://usableasp.net
>
>
> "guy" <guy@discussions.microsoft.com> wrote in message
> news:5CFC33E7-CEBA-44C2-9A53-4C6C244E74EE@microsoft.com...
> > Michael,
> > AutoGenerateEditButton is already true,
> > and ithe edit button appears, What do I need to do in the RowEditing event
> > to actually edit the data?
> >
> > Guy
> >
> > "Michael Nemtsev" <Michael Nemtsev>, "MVP" wrote:
> >
> >> Hello guy,
> >>
> >> try to set the AutoGenerateEditButton = true;
> >>
> >> ---
> >> WBR,
> >> Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour
> >>
> >> "The greatest danger for most of us is not that our aim is too high and
> >> we
> >> miss it, but that it is too low and we reach it" (c) Michelangelo
> >>
> >>
> >> g> How do you enable editing in a GridView programatically rather than
> >> g> via its Tasks menu?
> >> g>
> >> g> Guy
> >> g>
> >>
> >>
> >>

>
>
>

Reply With Quote
Reply


Thread Tools

Similar Threads

Thread Thread Starter Forum Replies Last Post
GridView - two clicks needed to enter in-place editing Hrvoje Vrbanc DOTNET 9 09-16-2008 04:34 AM
Editing gridview Mike P DOTNET 4 10-31-2007 05:32 AM
Editing Single Cell on GridView jack DOTNET 5 09-14-2007 07:25 AM
GridView Control - Disable/Enable Row Editing Mel DOTNET 1 07-30-2007 09:41 AM
editing in gridview vinodkus@gmail.com DOTNET 2 07-17-2007 06:02 AM


All times are GMT -5. The time now is 09:00 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.