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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataGrid/Datalist Formatting question

Status
Not open for further replies.

AppzDev

MIS
Oct 9, 2002
57
0
0
US
I'm thinking it's pretty simple what i want to do, however seeing as i don't know how to do it, makes it more difficult. Anyways...

I want to create a datagrid or a datalist...whichever allows the most flexibility and need it to look like this.


|DATE1 | DATE2 | DATE3 |
------------------------------------
VALUE1 | 15 | | |
------------------------------------
VALUE2 | | 16 | |

Where along the vertical side there are values and along the top there is a defined date "Field" that is taken from the database.

To clarify. In the database there is a field called "Last Visit Date" which is what i want to display on the top of the grid exemplified by Date1, Date2, Date3 above. Using that "Date" i want it to grab the values associated with it.

What is easier/more user friendly to look into? Datagrids or Datalists? Or, if anyone has other suggestions, please let me know..as always, any replies are appreciated.

Thanks again!

dc~
 
I am using datalists to display my data from a stored proc in my SQL Server. I feel more comfortable with it. Just define a connection, data adapter (the stored proc or table you wanted to access from the server), define and fill a dataset, then bind it to your datalist object.

-----------------------------------------------------------
Here's a sample,

In the HTML side: Drag and drop a datalist in the design grid, then in the HTML code, type this inside the form tag.

<Form>
<asp:datalist ID=&quot;Sample&quot; runat=&quot;server&quot; width=&quot;470px&quot;>
<! This is for your column name/title>
<Header Template>
<table width=&quot;90%&quot;>
<tr>
<th width=&quot;30%&quot;>Date1</th>
<th width=&quot;30%&quot;>Date2</th>
<th width=&quot;30%&quot;>Date3</th>
</tr>
</table>
</Header Template>

<! This is optional if you wanted to put designs>
<AlternatingItemStyle BackColor=&quot;Gainsboro&quot;>
</AlternatingItemStyle>

<!This is for your data>
<Item Template>
<table width=&quot;90%&quot;>
<tr>
<td width=&quot;30%&quot;>Value1<%#Container.Dataitem(&quot;Date1&quot;)%>
</td>
<td width=&quot;30%&quot;>Value2<%#Container.Dataitem(&quot;Date2&quot;)%>
</td>
<td width=&quot;30%&quot;>Value3<%#Container.Dataitem(&quot;Date3&quot;)%>
</td>
</tr>
</table>
</Item Template>
</asp:Datalist>
</form>

In your code (Sample.aspx.vb):

Imports System.Data.SqlClient

Public Class Sample
Inherits System.Web.UI.Page
'This automatically is defined when your drag a datalist
'on the grid in design
Protected WithEvents DeliveryDetails As
System.Web.UI.WebControls.DataList

'Connection
Dim sqlString As String = &quot;Data Source=server-name; &quot; & _
&quot;Initial Catalog=dbase-name; UID=UserID;Pwd=password&quot;
Dim dbconn As SqlConnection = New SqlConnection(sqlString)
Dim sda As SqlDataAdapter
Dim ds As New DataSet()

'On Initial Page Load
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then

'The &quot;Table&quot; could be a table, view, stored proc containing
'the data you want displayed.

sda = New SqlDataAdapter(&quot;Table&quot;, dbconn)
ds.clear() 'Just to make sure the dataset is clear
sda.fill(ds) 'Fill the dataset with the &quot;Table&quot; data
Dim dv As New DataView(ds.Tables(0)) 'define a dataview

'Sample is your datalist name
Sample.DataSource = dv 'Put dv as your datalist source
Sample.DataBind()
End if

End Sub

End Class

----------------------------------------------------------

This is it :))
Hope this helps,
Doodie

 
Ok, i tried that out and it worked great, however, i think i left out one important factor in the original question.

Let me see if i can clarify it...it's difficult when i can't show someone.

Ok, the user picks a person from a list and chooses &quot;View Results&quot;

This in turn displays a datagrid or datalist in which ALL of the Lab Values in the tblValues table are chosen based on pt_id. So, for example, i choose myself. I've had 3 seperate Results on let's say 07/07/2003, 07/08/2003, and 07/09/2003. The results i want to display are based on the &quot;Date of Lab&quot; or the 3 dates above. Let's say these results are WBC and RBC. The Select statement would return:

pt_id lab_date RBC WBC
123 07/07/2003 50 50
123 07/08/2003 100 100
123 07/09/2003 150 150

So, when i display the Datagrid or Datalist, the &quot;header&quot; in this case has to be the dates taken from a database and those dates have values that go along with them.

So, i am looking to get the datagrid/datalist to look like:

07/07/2003 07/08/2003 07/09/2003
RBC 50 100 150
WBC 50 100 150

I hope i explained it a bit better than before, and i hope even more that someone out there can at least point me in the right direction. Being a noob at this is frustrating at times.

Doodie, the code you gave me above is already going to help me tremendously so thank you very much. It is GREATLY appreciated.

dc~
 
What you need here is to create a pivot table or crosstab query in a stored proc that takes the result type (RBC & WBC) as the row heading and date as the column heading, then include a parameter of person's name.

I'll check if I have a sample sql code for this, and get back on you soonest...

Doodie :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top