?
Solved

Two clicks required to edit values in webform datagrid?

Posted on 2011-10-13
5
Medium Priority
?
348 Views
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?

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
Comment
Question by:codefinger
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36966452
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
 

Author Comment

by:codefinger
ID: 36966521
Those are some great tips, but I don't see my problem mentioned.
0
 
LVL 16

Expert Comment

by:Easwaran Paramasivam
ID: 36966600
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
 

Author Comment

by:codefinger
ID: 36966642
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
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 36967195
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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
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.
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

862 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