Update a gridview row without edit

I work with C #
I want update my columns in my GridView without going through edit :
for each row I click update button to update the line

how? Thank you.
3/9/2009 12:41:10 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

7 Replies

Similar Articles

[PageSpeed] 46

This is easy enough to do. First, you need to add your input controls into TemplateFields instead of BoundFields. Secondly, you then need to add your own Update Button within another TemplateField setting the CommandName property to something of your choosing. Next, capture this event within the the GridView.RowCommand handler and update your row accordingly.

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

3/9/2009 12:49:26 PM

Check this article this gives you good idea on how to do it.




3/9/2009 3:09:00 PM

Thank you ecbruck and  SurendraKishore :)

HowTo get the value of a cell using RowCommand ?

for example to update with edit(GridView_RowUpdating) we  writing 

       t1= ((Label)(GridView1.Rows[e.RowIndex].Cells[0].FindControl("id0")));
3/13/2009 9:34:23 AM

You could try something like this: 

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    Button btn = e.CommandSource as Button;
    GridViewRow row = btn.NamingContainer as GridViewRow;

    if (row != null)
        TextBox txt = row.FindControl("TextBox1") as TextBox;

        if (txt != null)
            // Do something here

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

3/13/2009 11:59:17 AM
Thank you very much ecbruck :) merci.
3/13/2009 12:59:53 PM

I have another problem I could not select a row in the GridView whenI click select i have this message:Object reference not set to an instance in  

GridViewRow row = btn.NamingContainer as GridViewRow;I have this message if I select a line  by using JavaScrip or _SelectedIndexChanged. this is my code :

public void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

        Button btn = e.CommandSource as Button;
        GridViewRow row = btn.NamingContainer as GridViewRow;

        if (row != null)
            Label l1 = row.FindControl("id01") as Label;
            Label l2 = row.FindControl("id41") as Label;

            SqlConnection myConnection = new SqlConnection(ConnectionString);

            SqlCommand myCommand = new SqlCommand("PS_fa", myConnection);

            myCommand.CommandType = CommandType.StoredProcedure;

            myCommand.Parameters.Add(new SqlParameter("@CODE_fa", SqlDbType.VarChar, 4));

            myCommand.Parameters["@CODE_fa"].Value = l1.Text;
            myCommand.Parameters.Add(new SqlParameter("@CODE_pd", SqlDbType.VarChar, 4));

            myCommand.Parameters["@CODE_pd"].Value = l2.Text;



            GridView1.EditIndex = -1;


help me .


3/16/2009 11:04:22 AM

If you are selecting a row, use the GridView.SelectedIndexChanged event handler instead of the RowCommand handler. With this, you can retrieve the row like so: 

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    GridViewRow row = GridView1.SelectedRow;

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

3/16/2009 12:09:24 PM

Similar Artilces:

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

Allow editing of all rows simultaniously (without having to click edit/update for each row)?
I have an application where the user will be presented with perhaps 20 rows.  1 field of each row (the score) will need to be updated by the user.   Now with a gridview they would click on the first row's EDIT button then make the change for the Score field and then click update. Having to do this ~20 times would be somewhat annoying for the user :)  Is there any way I can get an Excel like behavior where the user can just click on the first row's Score field then enter the integer score and hit tab or down arrow or something and drop down to the next one and keep ...

Gridview : How to Edit the row in Gridview (update)
I have Gridview in which I'm displaying the row, I wanted to update/Modify the row  using custom button not with the link 'Edit' when I enable AutoGenerateEditButton ="true" Whenever user clicks on the Button, (ImageButton), it has to fire the event 'Gridview1_RowEditing'  Any help on this will be appreciated.    Your ImageButton simply needs to have its CommandName property set to "Edit".Thanks, EdMicrosoft MVP - ASP/ASP.NET  I am using one such logic, <asp:TemplateField HeaderText="Edit" Show...

After hitting update on gridview, data changes but gridview still shows the update and cancel links for edited row
Really weird. I click the update link after I change the input data. I debug through it and it shows that the update is complete but then when OnRowUpdating function is done the update and cancel links are still there. What else do I need to do.. Here is the code. ASP:  <asp:GridView ID="OOWSecAuth" runat="server" AutoGenerateColumns="false" ShowFooter="true" AutoGenerateEditButton="true" OnRowEditing="OOWSecAuthEdit" OnRowUpdating="OOWSecAuthUpdate" ...

Updating and binding control to other controls within the same row of a GridView
HiIn the EditTemplate of my GridView I show 2 DropDownLists. When the user selects the first dropdownlist, I need it to update the contents of the second dropdownlist. I have my Subs that do this fine when not inside the GridView, but what is the correct way to do it whilst they are in the GridView?This is my current attempt that returns the error 'Object reference not set to an instance of an object'. I presume its related to correctly targeting the DropDownList in question? This is my GridView:<asp:GridView ID="GridView1" runat="server"  &...

How to Edit & update & Delete a particular row of Gridview with code in c# & without using SQLDataSource
Hi Everyone           i have to take a gridview and to do the following operation              1)Insert new row in gridview by click on Add New Button in gridview            2)Edit that new row            3)Update that new row           4)Delete That new row how to write code for this.plz help thanks & regards rakesh    ...

GridView : how to Highlight the last edited Row in gridview and update Dropdrown
never mine i solve the prob. thanks Hi there,I think you are determining the edited row as:int index = GridView1.EditIndex;After finishing the update you must doing GridView1.DataBind();With in your update procedure last statement should be:GridView1.SelectedIndex = index;If you want to update the dropdown just say:DropDownList1.Items.Clear();DropDownList1.DataBind();Hope this helps,thanks,Murthy here Dont forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so we will all know you have be...

How to get the data of a particular row in gridview without editing that row.
I have a gridview in a page in that ihave hyperlink as one column on click of that i want to go next page with the data present in that corresponding row. How shell i read the data from grid view for that pirticular row.On which event i can get the data. HI, the row that is selected should be passed into a string or an array or in sessionsthis can be done through this code  protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)    {        Label _lbl = new Label();      &...

Direct editing of gridView or Ddatagrid controls without clicking on an EDIT link
I have an application where lots of data is presented to the user in a gridView control and the user needs the option to review and overwrite any values in the cells of the grid.  My users find it very annoying and time consuming to click on an edit link to turn a row of the gridView into edit mode.  Typically, they might jump around and edit a few values in several rows.  Is there any way to present the data in a gridView control, datagrid control or something that looks like a grid where the entire grid is already in edit mode?  Can you make a grid that cont...

ListView onclick edit row without Edit link problem (GridView worked...)
Hello,I was initially using a GridView to enable row editing when any element of the row was clicked.  I'm using this control inside an UpdatePanel for partial-page postbacks.  This was basically accomplished by: protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {//... if (e.Row.RowType == DataControlRowType.DataRow) { string jsCommand = string.Format("if ({2} != {1}) __doPostBack('{0}','Edit${1}')", GridView1.ID, e.Row.RowIndex, GridView1.EditIndex); foreach (TableCell c in e.Row.Cells) { // OnClick enable the e...

why can't Gridview update if empty data is presented into the textfield of Gridview edit
 HI all,I have basically two fields which are Name,description. Whenever I was trying to edit fields(name, description) the command event is not firing because description(textbox) is empty. Why and how to fix this issuse. Because Name field is a required one and description is optional it could be empty one. Any help please thanks and regards,Vijaycanaan.  Can you please give your code. This can help us understand and solve your problem!! Here is the code   <asp:GridView ID="GridView1" runat="server" AllowPaging="True" Aut...

edit and update a gridview control
Hi, Here's my question: The gridview shows all the items the student has already learned. Can the gridview be updated to add new data? For instance, the user wants to add another piece of item to learn and give a brief reason? I will add the dropdownlist and textbox control to the gridview (in edit mode, I assume)The dropdownlist will be bound to a datasource. Once the user has made a selection and typed a reason in the textbox, they will update the gridview to show what they have done. AFter they see that, they click a button which will launch a new page with the gridvi...

GridView does not update editable row
Hello I have used a gridview control to list and edit some items on the list. I have turned on the "Enable Editing" mode on the Gridview but the data is not updated when it comes to editable view. Instead it returns with original data as there is no change on the items. My code is like the one below: <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="MasrafDetayId" DataSourceID="SqlDataSource1"><Columns><asp:CommandField ShowEditButton="True" /><asp:BoundField DataField="MasrafDetayId" HeaderText="MasrafDetayId" InsertVisi...

how to edit,update row in gridview
plz send me sample code for gridview edit and update row.  U can find everything about grid view here..http://www.gridviewguy.com/CategoryDetails.aspx?categoryID=2_Datagrid,_DataList_and_Repeator_Control Hope it helps.-Manas=======================================If this post is useful to you, please mark it as answer. jeevanmummadi:plz send me sample code for gridview edit and update row. If using ADO.NEThttp://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspxIf using SqlDataSourcehttp://www.codersource.net/asp_net_grid_view_whidbey.aspx More about Data Acce...

Web resources about - Update a gridview row without edit - asp.net.presentation-controls

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012

DotNetKicks.com - Upcoming stories
DotNetKicks.com is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 12/30/2015 1:59:44 AM