Question Manually create a DataGrid without using the DataGrid control

steveb46

Member
Joined
Aug 5, 2010
Messages
15
Programming Experience
Beginner
I've done this in classic asp, but I'm trying to figure out how to do it in asp.net.

I have a file that is written to on the web server.

I need to read in this file and build a 10 column html.

This is a sample of the file I'm reading from (we didn't want to use a database because of all the hassles that go along with that):

My style|10 column bar chart|9/16/2010 9:59:53 AM||9/16/2010 9:59:53 AM||1|Column|PANTONE_BLACK_CV|33.9|25.1
chart1|my chart style|9/16/2010 10:06:07 AM|sball|9/16/2010 10:06:07 AM|sball|1|Column|PANTONE_BLACK_CV|33.9|25.1
steve5|My chart style here|9/16/2010 10:18:06 AM|sball|9/16/2010 10:18:06 AM|sball|1|Column|PANTONE_BLACK_CV|33.9|25.1

The "|" separate values, each entry, starts with a new line. I have two questions:

1. Anyway, I need to build a HTML table from this data. I used to use response.write before (in classic asp), but if I do that, the content gets written to the top of the page, not where I want it. How can I control its placement?

2. I would also like the to add some buttons to the top of this form, so they can sort by various things. For example, if the want to reverse sort, or sort by a column. How best (and easiest way) to approach this?
 
I found a sample on this site using a placeholder control. So you can skip the 1st question. Although I've got an issue with style. For some reason, when I view the source I have: <table css="table" border="0"> I get a border around the whole table (don't know where the border="0" is coming from???

I have in my style sheet:

table
{
border-style: solid;
border-width: 1px;
border-color: Black;
width: 100%;
padding: 1px;


}

Here's the code from aspx.vb page:

Imports System.IO

Partial Class Default3
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
PlaceHolder1.Controls.Clear()
Dim mytable As New Table
PlaceHolder1.Controls.Add(mytable)

mytable.Attributes.Add("css", "table")

Dim i, x
Dim record()
Dim crec()



record = Split(File.ReadAllText(System.AppDomain.CurrentDomain.BaseDirectory() & "master.txt"), vbCrLf)

For i = 0 To UBound(record) - 1
Dim tr As New TableRow
crec = Split(record(i), "|")

For x = 0 To 8
Dim tc As New TableCell
Dim mylabel1 As New Label
mylabel1.Text = crec(x)
tc.Controls.Add(mylabel1)
'tc.Style.Add(HtmlTextWriterStyle.BorderWidth, "1")
tr.Cells.Add(tc)
Next

mytable.Rows.Add(tr)

Next
End Sub
End Class
 
table style should be either class or element ID ... otherwise the style you have there will be applied to all table elements to your page.
However in this case i would suggest a CSS class (notice the dot upfront) e.g.

VB.NET:
.MyTable
{
    border-style: solid;
    border-width: 1px;
    border-color: Black;
    width: 100%;
    padding: 1px;
}

Then apply as attribute:

VB.NET:
mytable.Attributes.Add("class", "MyTable")
 

Latest posts

Back
Top