Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is there a way loop through the rows/records in an unbound gridview once it is filled?

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
I have a grid that gets filterd based on two drop down lists. One has managers names the other has week Ending Dates. I want to loop through the grid and find a value in column 'Timesheet' where it it 'NOT IN'. if so then grab their name which is columns ResourceFirstName and ResourceLastName.

Code:
this is in page load
        Dim SQLString As String = FillGridWhoseinsofarWithSQL(Me.ddlManagerName.Text,
                                                              Me.ddlWeekEndDate.Text,
                                                              "Counter",
                                                              ViewState("SortDirection"))

        Me.GridView1.DataSource = PopulateGridwithSQL(SQLString)
        Me.GridView1.DataBind()
'-------------
  Private Function FillGridWhoseinsofarWithSQL(ByVal Manager,
                                                 ByVal WeekEndDate,
                                                ByVal SortColumn,
                                                 ByVal SortDirection)

        Dim SQLString As String = ""
        If SortColumn = vbNullString Then
            SortColumn = "ResourcelastName"
        End If
        If SortDirection = vbNullString Then
            SortDirection = "ASC"
        End If

        If Manager = "Choose..." Then
            sp_SOWInsertWeekAtAGlance("NULL", WeekEndDate) 'NOTE this is "NULL" in quotes which the SP is looking for
        Else
            sp_SOWInsertWeekAtAGlance(Manager, WeekEndDate)
        End If

        SQLString = "Select ROW_NUMBER() OVER (ORDER BY WAGM.Vendor,WAGM.ResourceLastName,WAGM.ResourceFirstName) AS Counter, " & _
                    "WAGM.Vendor,WAGM.ResourceLastName, WAGM.ResourceFirstName, WAGM.Manager, " & _
                    "  WAG.TotalHours,  " & _
                    "Convert(nvarchar(12),WAG.WeekEndDate,101) AS WeekEndDate, " & _
                        "'Timesheet' = " & _
                    "Case  " & _
                        "When WAG.ResourceFirstName IS NULL Then 'NOT IN' " & _
                        "Else 'IN' " & _
                        " End , convert(nvarchar(12),WAG.TimeSheetSubmittedDate,101) as DateSubmitted " & _
                        "From WeekAtAGlanceMissing WAGM " & _
                            "left join WeekAtAGlance WAG ON " & _
                        "WAGM.ResourceLastName = WAG.ResourceLastName " & _
                        "And  " & _
                        "WAGM.ResourceFirstName = WAG.ResourceFirstName " & _
                        "Where WAGM.Vendor is not null"

        FillGridWhoseinsofarWithSQL = SQLString

    End Function
'-------------------
  Public Function PopulateGridwithSQL(ByVal SQLStatement As String)
        Dim Conn As SqlConnection
        'use ConnectionString from WEB config file
        Dim connStr As String = ConfigurationManager.ConnectionStrings("SOWTimeReportingConnectionString").ConnectionString

        Conn = New SqlConnection(connStr)
        Conn.Open()

        Dim daTrans As New SqlDataAdapter
        Dim dtTrans As New DataTable

        daTrans.SelectCommand = New SqlCommand(SQLStatement, Conn)
        daTrans.Fill(dtTrans)
        '
        Return dtTrans
        Conn = Nothing

    End Function

DougP
 
You can loop through the grid, but it could get messy. It is much easier to just loop through the datable that you are binding to the grid.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top