Two clicks required to edit values in webform datagrid?

Posted on 2011-10-13
Last Modified: 2012-05-12
In a datagridview on a webform I have let it autogenerate an Edit button for each row, then I pop up a separate window for editing the row when the RowEditing event begins (user clicks on the Edit button).  The datagridview itself is not editable.

However, I did NOT let it auto-generate a SELECT button, assuming that clicking EDIT on a row would automatically select it...however, that does not seem to be the case.  No matter which Edit button is clicked on the web form, the values collected and sent to the new window come from the first row, NOT the row where the edit button was clicked.

Is an additional SELECT button required to select a row for editing?  IOW, does the user actually have to click two buttons to begin the edit process?

What am I missing?


Private Sub GridViewRegistrants_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridViewRegistrants.RowEditing

        Dim ckbx As New CheckBox

        Dim d_obj As New MyChartRegistration.BDL.DOBJ.DataObjects.PatientRegistration

        d_obj.RecordID = CInt(GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_RECORDID).Text)
        d_obj.FirstName = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_FIRSTNAME).Text
        d_obj.LastName = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_LASTNAME).Text
        d_obj.Address1 = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_ADDRESS1).Text
        d_obj.Address2 = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_ADDRESS2).Text

        d_obj.City = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_CITY).Text
        d_obj.State = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_STATE).Text
        d_obj.Zip = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_ZIP).Text
        d_obj.ClinicNo = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_CLINICNO).Text
        d_obj.DOB = CDate(GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_DOB).Text)
        d_obj.Email = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_EMAIL).Text
        d_obj.EpicActCode = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_EPIC_ACT_CODE).Text
        d_obj.Gender = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_GENDER).Text
        d_obj.Phone_Number = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_PHONE_NUMBER).Text
        d_obj.SSN = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_SSN).Text

        d_obj.Status = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_STATUS).Text
        d_obj.Status_Updated_By = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_STATUS_UPDATED_BY).Text
        d_obj.Status_Updated_On = CDate(GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_STATUS_UPDATED_ON).Text)
        d_obj.Notes = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_NOTES).Text

        '  d_obj.Denial_Email_Sent = CBool(GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_DENIAL_EMAIL_SENT).)

        Dim RowCheckBox As CheckBox = GridViewRegistrants.SelectedRow.Cells(Me.ColumnsByNumber_DENIAL_EMAIL_SENT).Controls(0)

        If RowCheckBox.Checked Then
            d_obj.Denial_Email_Sent = True
            d_obj.Denial_Email_Sent = False
        End If

        Session("CurrentRecordID") = d_obj.RecordID

        Session("PatientDetails") = d_obj


    End Sub

Open in new window

Question by:codefinger
    LVL 16

    Expert Comment

    by:Easwaran Paramasivam
    I've already written an article contains some tips here

    Your problem is mentioned with solution please check it out.

    Author Comment

    Those are some great tips, but I don't see my problem mentioned.
    LVL 16

    Expert Comment

    by:Easwaran Paramasivam
    It is there:

    In a Grid link button (for example, clicking on Filename link button), a single click is not working sometimes.  Instead double clicking is working.

    The events should be bound to the link button while data bound itself using onItemDataBound event.
    In client side:

     <asp:DataGrid ID="grdResources" runat="server" AutoGenerateColumns="False"
     Width="100%" DataKeyField="ResID" OnItemDataBound="grdResources_ItemDataBound">
    Toggle HighlightingOpen in New WindowSelect All
    In server side:

      protected void grdResources_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    Private const URL = "some file name";
       if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==  ListItemType.AlternatingItem)
        lnkSelect.Attributes.Add("onclick", "'" + URL + "'); return true;");

    Author Comment

    I'm sorry, I still don't see the connection.
    In my case, a click on an edit button "works" because the event IS activated, its just that the code to collect the values of the row that was clicked on picks up the first row, regardless of which row the edit button was clicked on.

    I only asked about two clicks because at this point, it looks like I have to also generate a SELECT button, so the user will have to first click the SELECT button, then the EDIT button on the same row.
    Hoping to find a better solution so the user only has to click one EDIT button on one row.

    (Also, FWIW, I have found the databound event is very unreliable when working with a webform.  Nothing is actually bound after the grid populates.)
    LVL 83

    Accepted Solution

    Try using the RowCommand event instead and use the e.CommandArguments which contains the rowindex of row where edit button was clicked.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now