Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / October 2007

Tip: Looking for answers? Try searching our database.

GridView -enable editing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
guy - 30 Oct 2007 09:37 GMT
How do you enable editing in a GridView programatically rather than via its
Tasks menu?

Guy
Michael Nemtsev, MVP - 30 Oct 2007 10:51 GMT
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>
guy - 30 Oct 2007 11:07 GMT
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,
>
[quoted text clipped - 12 lines]
> g> Guy
> g>
Michael Nemtsev, MVP - 30 Oct 2007 11:10 GMT
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,
>>
[quoted text clipped - 14 lines]
>> g> Guy
>> g>
Eliyahu Goldin - 30 Oct 2007 11:26 GMT
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.DataKeys[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(userToUpdate);

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(userToUpdate.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();

}

Signature

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

> Michael,
> AutoGenerateEditButton is already true,
[quoted text clipped - 22 lines]
>> g> Guy
>> g>
guy - 30 Oct 2007 11:47 GMT
Thanks Guys,
it was the resetting of the DataSource and re-binding that I was missing

cheers

Guy

> You need to handle 3 events. Here is an example for editing a grid with user
> info. Note using EditIndex property.
[quoted text clipped - 92 lines]
> >> g> Guy
> >> g>

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.