Click here to Skip to main content
16,016,168 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating an employee list with employee names listed under departments.

Executive
Mary Lamb
Ted George
Budget
Money Man
Deputy Paul

My datatable returns the department name for each person. How do i get it just once until it changes.

I havent really tried anything because I dont know how to do a comparison

Thank you!

What I have tried:

VB Code
If Not IsPostBack Then
           Dim dt As New DataTable()

           Dim groupid As Integer = 106
           Dim campusname As Label
           Dim campusnameCUrr As String = ""
           Dim campusNamePrev As String = ""

           'Dim lblCampus As Label = dlStaff.FindControl("lblcampus")
           Dim cmd As New SqlCommand("proc_Directory_Select_Full_byGroupId_test", strConn)


           cmd.CommandType = CommandType.StoredProcedure
           cmd.Parameters.AddWithValue("@Id", groupid)
           strConn.Open()
           Dim da As New SqlDataAdapter(cmd)
           da.Fill(dt)
           staff.DataSource = dt
           staff.DataBind()


           strConn.Close()
       End If



Asp.net code

<asp:datalist id="staff" runat="server">
  <itemtemplate>
      <asp:label id="campusname" runat="server" text='<%#Eval("campusname") %>' ></asp:label>
  </itemtemplate>

   </asp:datalist>
Posted
Updated 22-Aug-20 0:25am

1 solution

We don't know - and we can't tell you what to do.
The problem is that you are using a stored procedure we don't have access to to access data in tables we have no access to, to retrieve data we have no idea about (and your sample doesn't help - I have no idea if that is one row of 6 columns, or 6 rows of one column).
And then you need help with changes that don't make any sense either.

Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with, we get no context other than that.

You need to start by learning how to ask a question - no, I'm serious - because at the moment all of the questions you have asked assume a lot of information that you are privy to and that we aren't. Think of it this way: assume your car breaks down in the middle of nowhere and you ring the garage. You say "My car broke down, please come and fix it" then turn off your phone. How long are you going to be waiting until somebody arrives with the right bits to fix your exact car?

Go here: Asking questions is a skill[^] and read it really carefully. Then think about yoru problem and how you need to ask total strangers for help!
 
Share this answer
 
Comments
rlgentry 24-Aug-20 15:19pm    
I really didnt think that it mattered what my sql store proc is but to put it simply it would be
"select campusname, firstname, lastname from directory"

I would like to 'group' the firstname and lastname under the CampusName.
I decided I need 2 for loops but I only get the last record.


Code is
Dim campusname As Label = DirectCast(staff.Items(0).FindControl("campusname"), Label)
For Each row In dt.Rows

campusnameCUrr = row("campusname")
campusname.Text = campusnameCUrr
For j As Integer = 0 To dt.Rows.Count - 1
campusname.Text = campusnameCUrr
campusNamePrev = dt.Rows(j)(10).ToString()
If campusname.Text = campusNamePrev Then

Exit For


End If

Next


Next

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