How to allow edit a row in Gridview without using CommandField?

Hi all,

I have a textbox and a Dropdownlist in a Gridview.  Based on certain selected value of the dropdownlist, the textbox will be enable for editing.  Then, I need to re-calculate the values of all dropdownlists.   I was able to do all of that with the CommandField already.  However, since I have a lot of rows in the gridview, if I use the CommandField, the user will have to click the Edit button everytime he/she wants to edit a row.   Are there anyway I could do what I described without the button in my asp. 2.0 page?  Sample codes are appreciated.

Thanks a lot,

9/10/2007 6:58:33 PM 72751 articles. 3 followers. Follow

8 Replies

Similar Articles

[PageSpeed] 56
Do not forget to mark as answer all message who help you.

Don't forget to check if you can answer some of our question to.
9/10/2007 7:29:21 PM

Thank you, Wookie, for a good link.  Using that Bulk editing Gridview, I was able to create a editable gridview.  However, I don't know how to disable my textbox depending on the value of the dropdownlist.  Also, the index in dropdownlist of the selectedIndexChanged event is "out of range" when it's triggered.  Any suggestion? 

Below is my code: 

        SaveButtonID="SaveButton" >
         <asp:BoundField DataField="FactStdNum" HeaderText="Std" ReadOnly="True"  />
         <asp:BoundField DataField="FactStdText" HeaderText="Description" ReadOnly="True"  />
         <asp:BoundField DataField="StdComment" HeaderText="Comment"  />
                     <asp:TemplateField HeaderText="Score">  
                        <ControlStyle Width="40px" />
                                 <asp:DropDownList ID="ddlFactStdScore1" AutoPostBack="true"  runat="server" 
                                    SelectedValue='<%# Bind("FactStdScore") %>'
                                    AppendDataBoundItems="True" >
                                <asp:ListItem Value="1" Text="1" ></asp:ListItem>
                                <asp:ListItem Value="2" Text="2" ></asp:ListItem>
                                <asp:ListItem Value="3" Text="3" ></asp:ListItem>
                                <asp:ListItem Value="4" Text="4" ></asp:ListItem>
                                <asp:ListItem Value="0" Text="N/A" ></asp:ListItem>
                                <asp:Label ID="lblFactStdScore7" runat="server" Text='<%# Eval ("FactStdScore") %>'></asp:Label>

    Protected Sub ddlFactStdScore1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ddl As DropDownList = DirectCast(sender, DropDownList)
        Dim index As Integer = gvFactor1.EditIndex
        Dim selectedRow As GridViewRow = gvFactor1.Rows(index) 'Error here: index is out of range <----
        Dim validator As RequiredFieldValidator = CType(selectedRow.FindControl("reqValComment1"), RequiredFieldValidator)
        Dim lblFactStdNum As Label = CType(selectedRow.FindControl("FactStdNum"), Label)
        Dim txtStdComment As TextBox = CType(selectedRow.FindControl("StdComment"), TextBox)
        If ddl.SelectedValue > 2 Then
            validator.ValidationGroup = "Comment"
            txtStdComment.Visible = True
            validator.ValidationGroup = "none"
            txtStdComment.Visible = False
        End If
    End Sub

 Thanks a lot,



9/10/2007 9:55:24 PM

Hi JP,

Do it on RowDataBound.

if (e.Row.RowType == DataControlRowType.DataRow)


TextBox myTextBox = e.Row.FindControl("StdComment") as TextBox;

DropDownList myDDL = e.Row.FindControl("ddlFactStdScore1") as DropDownList;

if (myDDL.SelectedValue > 2)


myTextBox.Visible =






Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question.
View Blog
9/11/2007 10:30:21 AM

Hi Naveen,

Thanks a lot for responding.  I put RowDataBound event for my Gridview but when a value in the Dropdownlist is selected, the SelectedIndexChanged is fired first and I got the error message "index is out of bound" at this line:

Dim selectedRow As GridViewRow = gvFactor1.Rows(index)

Any ideas?


9/11/2007 2:32:36 PM


why dont you just rebind the data in the selected index changed?
Do not forget to mark as answer all message who help you.

Don't forget to check if you can answer some of our question to.
9/11/2007 2:54:09 PM

Thanks, Wookie.  I don't understand rebinding here.  Can you give me an example?


9/11/2007 3:40:08 PM


Do not forget to mark as answer all message who help you.

Don't forget to check if you can answer some of our question to.
9/12/2007 1:46:18 PM

Thank you Wookie and Naveeni for helping me.  I found the solution for my issue at  It's a different approach yet simple for me.  Case is closed.


9/13/2007 3:33:07 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 ...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

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 editing without using data source controls?
I am binding my gridview without using a datasource control and instead doing it in the code behind. However, I would like to use the inline editing features of the gridview. Could someone please point me to an example that does gridview editing/updating 'manually' in the code behind? Thanks,Tim just create an object data source on your page and point it to a Class that acts as a BLL . in that class make public methods like: updateTHECLASS()insertTHECLASS()deleteTHECLASS() and in the object data sources insert, update, and delete methods put in those public methods you made in...

Trying to use the FAQ " Sorting and paging in the GridView control when not using data source controls "Sorting and paging in the GridView control when not using..."
and I am not getting the results I had hoped for.  I keep getting a "Compiler Error Message: CS0123: No overload for 'AdhocJobGridView_PageIndexChanged' matches delegate 'System.EventHandler'".   Here is my event handling... protected void AdhocJobGridView_PageIndexChanged(object sender, GridViewPageEventArgs e){ try { AdhocJobGridView.DataSource = wsBaseInfoArray; AdhocJobGridView.PageIndex = e.NewPageIndex; AdhocJobGridView.DataBind(); }catch (Exception ex) {throw ex; }   Here is my aspx... <asp:GridView ID="AdhocJobGridView...

how to edit rows in the gridview contol in windows form using
 hi, I'm neha and can anybody pls tell me how to edit the rows listed in gridview control in windows form using Its urgent . Thanks,Neha  In this lesson, you will learn about the GridView and FormView controls and how you can use some of the features of these controls to make editing and displaying of database content easier remember to click “Mark as Answer” on the post that helps you nehakhanna:gridview control in windows form These forums are for ASP.NET (web sites / web applications), not wind...

how can I delete a row from gridview in code-behind page without using sqldatasource control?
Hi, I have image button in my gridview. and I put its command name property 'delete'. could you please tell me what code should I have in my code behind page to delete row? I don't use sqldatasource for databound I use dataset. I use VB for coding. Thanks. Something like this: Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand If (e.CommandName.Equals("delete")) Then Dim btn As ImageButton = TryCast(e.CommandSource, ImageButton) If btn IsNot Nothing...

Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once?
 Hi Is there a control that offers the same data presentation as a GridView, but allows users to copy and paste many rows/columns at once onto the grid? What I mean is some grid that 's as flexible as MS Excel grid for example.  Any suggestions will be very much appreciated.E The Repeater control is a highly customisable data presentation controlRohin.NET developerNever trust a computer you can't throw out a window. - Steve WozniakPlease remember to click on 'Mark as answer', if this post helped you......

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    ...

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

Can I populate a Gridview outside of the Gridview using my own edit controls ?
I want to be able to populate a GridView control through some edit controls that willbe displayed above my GridView control. Is their a way to do this without using a DetailsView control ? (Refer to the following article) Or can I have my own edit controls seperately from the GridView control? Actually, all you need to do is to put some textboxes and button. Than on button click insert that data in database and bind data to your gridviewagain. __Please mark post as answer if it helps, if not come back and a...

Using GridView to edit and update the Data without using SqlDataSource
Hi,  I am new to ASP .Net. I am having a GridView control and I want to bind data to GridView using DataSet.   SqlDataSource should not be used because it should be done programatically.  Also, the GridView should also support editing the data and update the same into the database.  Can you supply me with a piece of code .     Regards, Rajesh KalidindiMicrosoft Certified Technology Specialist Try to search in google for dynamic add record to gridview , choose ur code language following is one of the link i found

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...

How can I allow a user without edit permission to access a control which is of type edit?
Hello,I have a module which allows a user with Edit permission to add a new record or update a record in the database.  I would also like to be able to allow user's without Edit permission to Add and Update records they created.In the view module's "ModuleActions" method I can add the following action:actions.Add(GetNextActionID(), Localization.GetString(ModuleActionType.AddContent, LocalResourceFile), ModuleActionType.AddContent, "", "", EditUrl(), False, DotNetNuke.Security.SecurityAccessLevel.View, True, False) This allows the user's without Edit permission to see the "Add Recor...

Web resources about - How to allow edit a row in Gridview without using CommandField? -

Blog Archive
Blog Archive 2013 75 Essential Tools for iOS Developers Aug 15 2013 posted in iOS Speaking at Cocoa Conf PDX Jul 13 2013 posted in Speaking In ...

Resources last updated: 12/19/2015 12:12:01 PM