Click here to Skip to main content
15,895,256 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here I am comparing GridView2.Rows(i).Cells(3).Text with reader(0), but I am getting an error.
VB
Public Sub checkpipno()
        Dim i As Integer
        For i = 0 To GridView1.Rows.Count - 1
            Dim vr As String
            vr = GridView2.Rows(i).Cells(5).Text
            Dim village As String = GridView2.Rows(i).Cells(3).Text
            Dim con As New SqlConnection(connStr)
            con.Open()
            Dim sql As String = "SELECT pipno,pipcode1 FROM PIP_Entry WHERE Rpt_Unit = '" & village & "' "
            Dim cmd As New SqlCommand(sql, con)
            Dim reader As SqlDataReader = cmd.ExecuteReader()
            While reader.Read()
                If vr = reader(0).ToString() Then
                    GridView2.Rows(i).Cells(14).Text = reader(1).ToString()
                    GridView2.Rows(i).Cells(14).BackColor = System.Drawing.Color.FromName("Green")
                    GridView2.Rows(i).Cells(15).Text = "Done"
                    GridView2.Rows(i).Cells(15).BackColor = System.Drawing.Color.FromName("Green")
                End If
            End While
            reader.Close()
            con.Close()
        Next
    End Sub

The Above Code I have used to compare grid view row with other table value i.e., in reader(0), but here I am getting error in VB.NET.
'Rows' is not a member of 'System.Web.UI.WebControls.DataGrid'.

Post Solution for this Post
Posted
Updated 7-Mar-12 20:04pm
v3
Comments
André Kraak 8-Mar-12 2:04am    
Edited question:
Added pre tags
Spelling/Grammar

The error is clear. Datagrid[^] has now member called Rows. Verify Gridview1 and Gridview2 if they are really Gridview[^] controls or not.
 
Share this answer
 
The DataGrid control has an Items property to programmatically access the items in the control. An example to access the values in individual cells of each row of DataGrid is given here.

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.items.aspx[^]

You may vote and accept the solution if your problem is solved, otherwise please post your queries.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900