Answered by:
Clickable Gridview

Question
-
User643938055 posted
I know that I am missing some of the code that I need in order to get the gridview to be clickable and pull over the contact data, but I am stuck.
VB Code for GridView Binding:
'''''''''''''' 'Org Contacts' '''''''''''''' clsGlobal.sqlConn.Open() cmdOrgContacts = New SqlCommand("SELECT OrgContact.orgcontactid, dbo.udfGetPersonFullname(Person.personid) as Name, dbo.udfGetOrgContactRoles(OrgContact.orgcontactid) as Role, Specialty.SPEC_TITLE as Specialty " & _ "FROM OrgContact " & _ "INNER JOIN Person ON OrgContact.personid = Person.personid " & _ "LEFT JOIN PersonPhysician ON Person.personid = PersonPhysician.personid " & _ "LEFT JOIN Specialty ON PersonPhysician.specialtySID = Specialty.specialtySID " & _ "WHERE (OrgContact.orgid = " & dsOrg.Tables(0).Rows(ViewState("CurrentRow")).Item("orgid") & ") and (OrgContact.expired_dt is null) " & _ "ORDER BY [Name]", clsGlobal.sqlConn) drOrgContacts = cmdOrgContacts.ExecuteReader 'clear columns gvOrgContacts.Columns.Clear() 'add contact name column colButtonField = New ButtonField colButtonField.HeaderText = "Contact Name" colButtonField.HeaderStyle.HorizontalAlign = HorizontalAlign.Left colButtonField.ItemStyle.Width = New Unit(175) colButtonField.DataTextField = "Name" gvOrgContacts.Columns.Add(colButtonField) 'add contact role column colBoundField = New BoundField colBoundField.HeaderText = "Role(s)" colBoundField.HeaderStyle.HorizontalAlign = HorizontalAlign.Left colBoundField.ItemStyle.Width = New Unit(300) colBoundField.DataField = "Role" gvOrgContacts.Columns.Add(colBoundField) 'add specialty column colBoundField = New BoundField colBoundField.HeaderText = "Specialty" colBoundField.HeaderStyle.HorizontalAlign = HorizontalAlign.Left colBoundField.ItemStyle.Width = New Unit(200) colBoundField.DataField = "Specialty" gvOrgContacts.Columns.Add(colBoundField) 'bind contact gridview gvOrgContacts.DataSource = drOrgContacts gvOrgContacts.DataBind() clsGlobal.sqlConn.Close() End If End Sub
Code for Gridview Rommand (this is where I was trying to setup the ability to click):
Protected Sub gvOrgContacts_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvOrgContacts.RowCommand Dim i As Integer Dim SearchContactIds As String daSearch_Contact = New SqlDataAdapter(cmdSearch_Contact) dsSearch_Contact = New DataSet daSearch_Contact.Fill(dsSearch_Contact, "SearchContact") 'store dataset in ViewState so do not lose on PostBack ViewState("dsSearch_Contact") = dsSearch_Contact Session("SearchContactIds") = dsSearch_Contact.Tables(0).Rows(e.CommandArgument).Item("personid") Session("OrgChanged") = False 'store all orgid's in dsSearch_Contact in Session variable SearchContactIds = "" For i = 0 To dsSearch_Org.Tables(0).Rows.Count - 1 If SearchContactIds = "" Then SearchContactIds = dsSearch_Org.Tables(0).Rows(i).Item("personid") Else SearchContactIds = SearchContactIds & ", " & dsSearch_Org.Tables(0).Rows(i).Item("personid") End If Next Session("SearchContactIds") = SearchContactIds Response.Redirect("~/EditContact.aspx") End Sub
Thursday, July 14, 2011 3:58 PM
Answers
-
User-2010311731 posted
Here is a good tutorial that does something very similar...
Matt
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, July 14, 2011 5:52 PM
All replies
-
User-2010311731 posted
Here is a good tutorial that does something very similar...
Matt
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, July 14, 2011 5:52 PM -
User643938055 posted
I am wanting to create a session out of my gridview. I would like to store the Org Contact - personid information only and then pass it to the EditContact.aspx page.
I have tried this but it doesn't work.
Dim value As String = gvOrgContacts.SelectedValue value = Session("OrgContacts") Response.Redirect("EditContact.aspx")
Friday, July 15, 2011 3:25 PM