473,776 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView -enable editing

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

Guy
Oct 30 '07 #1
5 5139
Hello guy,

try to set the AutoGenerateEdi tButton = 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,
AutoGenerateEdi tButton 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 AutoGenerateEdi tButton = 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.EditIn dex 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,
gAutoGenerateEd itButton 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 AutoGenerateEdi tButton = 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_RowEdit ing(object sender, GridViewEditEve ntArgs e)

{

System.Web.UI.W ebControls.Grid View grid = sender as
System.Web.UI.W ebControls.Grid View;

grid.EditIndex = e.NewEditIndex;

grid.DataSource = System.Web.Secu rity.Membership .GetAllUsers();

grid.DataBind() ;

}

protected void dgUsers_RowUpda ting(object sender, GridViewUpdateE ventArgs e)

{

System.Web.UI.W ebControls.Grid View grid = sender as
System.Web.UI.W ebControls.Grid View;

System.Web.Secu rity.Membership User userToUpdate =
System.Web.Secu rity.Membership .GetUser(dgUser s.DataKeys[e.RowIndex].Value.ToString ());

userToUpdate.Em ail = (dgUsers.Rows[e.RowIndex].Cells[5].Controls[0] as
System.Web.UI.W ebControls.Text Box).Text;

System.Web.Secu rity.Membership .UpdateUser(use rToUpdate);

bool isAdministrator =
(dgUsers.Rows[e.RowIndex].Cells[4].FindControl("c hbAdministrator ") as
System.Web.UI.W ebControls.Chec kBox).Checked;

if (isAdministrato r)

System.Web.Secu rity.Roles.AddU serToRole (userToUpdate.U serName, "Admin");

else

System.Web.Secu rity.Roles.Remo veUserFromRole( userToUpdate.Us erName,
"rAdmin");

grid.EditIndex = -1;

grid.DataSource = System.Web.Secu rity.Membership .GetAllUsers();

grid.DataBind() ;

}
protected void dgUsers_RowCanc elingEdit(objec t sender,
GridViewCancelE ditEventArgs e)

{

System.Web.UI.W ebControls.Grid View grid = sender as
System.Web.UI.W ebControls.Grid View;

grid.EditIndex = -1;

grid.DataSource = System.Web.Secu rity.Membership .GetAllUsers();

grid.DataBind() ;

}

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"guy" <gu*@discussion s.microsoft.com wrote in message
news:5C******** *************** ***********@mic rosoft.com...
Michael,
AutoGenerateEdi tButton 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 AutoGenerateEdi tButton = 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_RowEdit ing(object sender, GridViewEditEve ntArgs e)

{

System.Web.UI.W ebControls.Grid View grid = sender as
System.Web.UI.W ebControls.Grid View;

grid.EditIndex = e.NewEditIndex;

grid.DataSource = System.Web.Secu rity.Membership .GetAllUsers();

grid.DataBind() ;

}

protected void dgUsers_RowUpda ting(object sender, GridViewUpdateE ventArgs e)

{

System.Web.UI.W ebControls.Grid View grid = sender as
System.Web.UI.W ebControls.Grid View;

System.Web.Secu rity.Membership User userToUpdate =
System.Web.Secu rity.Membership .GetUser(dgUser s.DataKeys[e.RowIndex].Value.ToString ());

userToUpdate.Em ail = (dgUsers.Rows[e.RowIndex].Cells[5].Controls[0] as
System.Web.UI.W ebControls.Text Box).Text;

System.Web.Secu rity.Membership .UpdateUser(use rToUpdate);

bool isAdministrator =
(dgUsers.Rows[e.RowIndex].Cells[4].FindControl("c hbAdministrator ") as
System.Web.UI.W ebControls.Chec kBox).Checked;

if (isAdministrato r)

System.Web.Secu rity.Roles.AddU serToRole (userToUpdate.U serName, "Admin");

else

System.Web.Secu rity.Roles.Remo veUserFromRole( userToUpdate.Us erName,
"rAdmin");

grid.EditIndex = -1;

grid.DataSource = System.Web.Secu rity.Membership .GetAllUsers();

grid.DataBind() ;

}
protected void dgUsers_RowCanc elingEdit(objec t sender,
GridViewCancelE ditEventArgs e)

{

System.Web.UI.W ebControls.Grid View grid = sender as
System.Web.UI.W ebControls.Grid View;

grid.EditIndex = -1;

grid.DataSource = System.Web.Secu rity.Membership .GetAllUsers();

grid.DataBind() ;

}

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"guy" <gu*@discussion s.microsoft.com wrote in message
news:5C******** *************** ***********@mic rosoft.com...
Michael,
AutoGenerateEdi tButton 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 AutoGenerateEdi tButton = 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
5677
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 GridView to allow entry of quantity and Y/N switch for
6
3041
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 current_row_key of Grid1... to the objectDataSource2 parameter? (so that the second grid, gets only the information to do with current row of grid1)
5
4839
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 automatically if the data doesn't change. But if records have been added or deleted then it looks as if some code is necessary: I've done this by using GridView.SelectedValue to get the key value of the currently selected Row and then by itterating...
1
5216
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 the GridView does not display. I've debugged the DataTable and even when it has data and is bound to the GridView, when the page loads the GridView is not displayed. I set the datasource and then bind the GridView. I've tried disabling the...
3
4605
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 datasource to this GridView in runtime. But I cannot
2
13201
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 fields to be included in the table, which is to be bound to the gridview. The web form looks like so (Don't worry about the stupidity of this web form for now.):
5
3007
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 list that corresponds with the number of pages, but I am unable to wire up the Selected Index Changed event. Auto PostBack is set to true and the page is posting back when the DDL is selected / chaged, but the event is never being called. Any...
0
4666
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 and also get the datakey (in my case personid) of the the rows selected. Please point me in the right direction. This is what i have so far but i have problem accessing the child gridview in the button click event Cheers, Shilpa. <asp:GridView...
6
5758
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 OnSelectedIndexChanged event set on it. This triggers just fine, but within the codebehind of the OnSelectedIndexChanged event, I need to scan through all the entries in the nested GridView (to see if the user changed a value to an already existing value in the...
3
5244
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 DataTable, I am using List of Objects. Here's one example: http://ryanolshan.com/technology/gridview-without-datasourcecontrol-datasource/
0
9464
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10289
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10120
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7471
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3622
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2860
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.