By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,496 Members | 1,268 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,496 IT Pros & Developers. It's quick & easy.

GridView -enable editing

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

Guy
Oct 30 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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
gHow do you enable editing in a GridView programatically rather than
gvia its Tasks menu?
g>
gGuy
g>
Oct 30 '07 #2

P: n/a
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
gHow do you enable editing in a GridView programatically rather than
gvia its Tasks menu?
g>
gGuy
g>
Oct 30 '07 #3

P: n/a
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
gMichael,
gAutoGenerateEditButton is already true,
gand ithe edit button appears, What do I need to do in the RowEditing
gevent
gto actually edit the data?
gGuy
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

gHow do you enable editing in a GridView programatically rather
than
gvia its Tasks menu?
g>
gGuy
g>

Oct 30 '07 #4

P: n/a
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" <gu*@discussions.microsoft.comwrote in message
news:5C**********************************@microsof t.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
gHow do you enable editing in a GridView programatically rather than
gvia its Tasks menu?
g>
gGuy
g>

Oct 30 '07 #5

P: n/a
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" <gu*@discussions.microsoft.comwrote in message
news:5C**********************************@microsof t.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
gHow do you enable editing in a GridView programatically rather than
gvia its Tasks menu?
g>
gGuy
g>


Oct 30 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.