Getting the value of cell in gridview when a row is selected

Can anyone help me in getting - value of cell in to some variable in gridview when a row is selected by clicking it anywhere on the row. I selected the row by ___doPostBack() method.



de1209Asked:
Who is Participating?
 
DreamMasterCommented:
drow("PremiseId") = Convert.ToInt16(gvSelectAddress.SelectedRow.Cells(1).Text) Should do the trick as I said in your other topic as well..

Regards,
Max.
0
 
Elvio Lujan.Net Senior DeveloperCommented:
       gv.SelectedRow.Cells[0].Text
0
 
de1209Author Commented:
Hi lem2802 ,
This is actually my code:

Private Sub CreateSelectionAsSessionTable()
        Dim dt As New DataTable
        Dim drow As DataRow

        dt.Columns.Add(New DataColumn("PremiseId", GetType(Integer)))
        dt.Columns.Add(New DataColumn("CustomerId", GetType(Integer)))
        dt.Columns.Add(New DataColumn("Addressline1", GetType(String)))
        dt.Columns.Add(New DataColumn("Name1", GetType(String)))
        dt.Columns.Add(New DataColumn("HomePhoneNumber", GetType(String)))
        dt.Columns.Add(New DataColumn("WorkPhoneNumber", GetType(String)))

        drow = dt.NewRow()

        Dim i As Integer = gvSelectAddress.SelectedIndex

        If i = -1 Then i = 1

        drow("PremiseId") = CType(gvSelectAddress.SelectedRow.Cells(1).Text, Integer)
        drow("addressline1") = gvSelectAddress.Rows(i).Cells(7).Text
        drow("name1") = gvSelectAddress.Rows(i).Cells(8).Text
        drow("HomePhoneNumber") = gvSelectAddress.Rows(i).Cells(9).Text
        drow("WorkPhoneNumber") = gvSelectAddress.Rows(i).Cells(10).Text

        dt.Rows.Add(drow)

        Sessions.SelectedDataTable = dt

    End Sub

I am trying to get the selected cell value in this datatable. The cell is in the first column of the selected row.
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Elvio Lujan.Net Senior DeveloperCommented:
this work?

        drow("PremiseId") = gvSelectAddress.SelectedRow.Cells(1).Text
        drow("addressline1") = gvSelectAddress.SelectedRow.Cells(7).Text
        drow("name1") = gvSelectAddress.SelectedRow.Cells(8).Text
        drow("HomePhoneNumber") = gvSelectAddress.SelectedRow.Cells(9).Text
        drow("WorkPhoneNumber") = gvSelectAddress.SelectedRow.Cells(10).Text
0
 
de1209Author Commented:
 dt.Columns.Add(New DataColumn("PremiseId", GetType(Integer)))

The value for column premiseId here is Integer

gvSelectAddress.SelectedRow.Cells(1).Text  
this should be converted to integer.
Here the grid is in the master page

0
 
de1209Author Commented:


drow("PremiseId") = Convert.ToInt16(val(gvSelectAddress.SelectedRow.Cells(1).Text) )

worked fine.
0
 
DreamMasterCommented:
Glad to have been helpfull...

Regards,
Max.
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.

All Courses

From novice to tech pro — start learning today.