2 Replies - 747 Views - Last Post: 21 September 2015 - 06:59 AM

#1 SoundWaves  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-June 15

Help with SQL Query Results in ItemDataBound event from Repeater

Posted 21 September 2015 - 06:29 AM

I have a nested Repeater control in a web form. The Parent repeater displays Departments. The Child currently displays employees in that department. I need to display the Name once along with the count of records they have within the department. I can do either one, but not both. Here is my code for the child repeater, I don't know how to get the count. I have tried various things but always come up with an exception from a null value.

Protected Sub rptWorkLoad_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles rptWorkLoad.ItemDataBound
        If (e.Item.ItemType = ListItemType.Item) Or (e.Item.ItemType = ListItemType.AlternatingItem) Then
            Dim rptWorkLoadChild As Repeater = DirectCast(e.Item.FindControl("rptWorkLoadChild"), Repeater)
            Dim dpt As String = CType(e.Item.FindControl("lblDeptWork"), Label).Text
            Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("WorkOrdersConString").ConnectionString)
                Using cmd As New SqlCommand()
                    cmd.CommandText = "SELECT assigned_to, COUNT(*) FROM npwo WHERE department = '" & dpt & "' AND status <> 'complete' GROUP BY assigned_to "
                    cmd.Connection = con
                    con.Open()
                    'Total = the count of records
                    rptWorkLoadChild.DataSource = cmd.ExecuteReader()
                    rptWorkLoadChild.DataBind()
                    con.Close()
                End Using
            End Using
        End If
    End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Help with SQL Query Results in ItemDataBound event from Repeater

#2 andrewsw  Icon User is online

  • lashings of ginger beer
  • member icon

Reputation: 6338
  • View blog
  • Posts: 25,560
  • Joined: 12-December 12

Re: Help with SQL Query Results in ItemDataBound event from Repeater

Posted 21 September 2015 - 06:43 AM

Is this for an ASP.NET WebForm?
Was This Post Helpful? 0
  • +
  • -

#3 SoundWaves  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 33
  • Joined: 01-June 15

Re: Help with SQL Query Results in ItemDataBound event from Repeater

Posted 21 September 2015 - 06:59 AM

View Postandrewsw, on 21 September 2015 - 06:43 AM, said:

Is this for an ASP.NET WebForm?


Yes, I posted it here because my problem was with the VB code and SQL query. If you feel it should be moved, that's completely understandable.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1