• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

Two clicks required to edit values in webform datagrid?

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?

Thanks...




 
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
        Else
            d_obj.Denial_Email_Sent = False
        End If

        Session("CurrentRecordID") = d_obj.RecordID


        Session("PatientDetails") = d_obj


        Response.Redirect("UserDetails.aspx")



    End Sub

Open in new window

0
codefinger
Asked:
codefinger
  • 2
  • 2
1 Solution
 
Easwaran ParamasivamCommented:
I've already written an article contains some tips here http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4148-Some-ASP-NET-Practical-tips.html.

Your problem is mentioned with solution please check it out.
0
 
codefingerAuthor Commented:
Those are some great tips, but I don't see my problem mentioned.
0
 
Easwaran ParamasivamCommented:
It is there:

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

Solution:
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", "javascript:window.open('" + URL + "'); return true;");
  }
}
0
 
codefingerAuthor Commented:
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.)
0
 
CodeCruiserCommented:
Try using the RowCommand event instead and use the e.CommandArguments which contains the rowindex of row where edit button was clicked.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowcommand.aspx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now