473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

GridView -enable editing

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

Guy
Oct 30 '07 #1
5 5105
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the...
6
by: Nalaka | last post by:
Hi, I have a gridView (grid1), which as a templateColumn. In the template column, I have put in a gridView (grid2) and a ObjectDataSource (objectDataSource2). Question is... How to I pass the...
5
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens...
1
by: joechipubik | last post by:
I have a GridView in a FormView that has as its datasource a DataTable that is stored in the session cache. When I first load the page the GridView is displayed correctly, but on subsequent loads...
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
2
by: antonyliu2002 | last post by:
I've been googling for some time, and could not find the solution to this problem. I am testing the paging feature of gridview. I have a very simple web form on which the user can select a few...
5
by: Andrew Robinson | last post by:
I am attempting to better automate a Pager Template within a GridView. I am succesfully skinning a Drop Down List withing my control (the DDL is added to my control). I correctly populate the item...
0
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
6
by: RobertTheProgrammer | last post by:
Hi folks, Here's a weird problem... I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the...
3
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.