setting header text for a datagrid?

M

Mad Scientist Jr

I am having a hard time figuring out how to set header text for a
datagrid - I have found a number of pages on it but none work. Some
seem to be for vb.net desktop applications not web.

Can someone help? Below is my code, I want to set the header text to:

"My<br>Header<br>One" for MyField1
"My<br>Header<br>Two" for MyField2
"My<br>Header<br>Three" for MyField3

Note that I would like the line breaks in there. Any help
appreciated...

Dim sbSQL As New StringBuilder
sbSQL.Append("SELECT [vbcrlf/]")
sbSQL.Append(" [ID], [vbcrlf/]")
sbSQL.Append(" MyField1, [vbcrlf/]")
sbSQL.Append(" CONVERT(decimal(10,2), MyField2) as MyField2,
[vbcrlf/]")
sbSQL.Append(" MyField3 [vbcrlf/]")
sbSQL.Append("FROM [vbcrlf/]")
sbSQL.Append(" MyTable [vbcrlf/]")
sbSQL.Replace("[vbcrlf/]", vbCrLf)
Dim DataSet1 As DataSet
DataSet1 = New DataSet
Dim SqlConnection1 As SqlConnection
Dim SqlDataAdapter1 As SqlDataAdapter
SqlConnection1 = New
SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("DbConnString"))
SqlDataAdapter1 = New SqlDataAdapter(sbSQL.ToString, SqlConnection1)
SqlDataAdapter1.Fill(DataSet1)
SqlConnection1.Close()
SqlConnection1.Dispose()
SqlDataAdapter1.Dispose()
DataView1 = DataSet1.Tables(0).DefaultView
DataGrid1.DataSource = DataView1
DataView1.Sort = "MyField2, MyField1, MyField3 "
DataGrid1.DataBind()
 
M

Mad Scientist Jr

I added some code, and am getting an error "Specified cast is not
valid."

version 1:
Call
sub_FillDataSet(System.Configuration.ConfigurationSettings.AppSettings.Get("dbConnString"),
sbSQL.ToString, DataSet1)
DataView1 = DataSet1.Tables(0).DefaultView
Dim DataGridColumn1 As DataGridColumn
Dim BoundColumn1 As BoundColumn
For Each DataGridColumn1 In DataGrid1.Columns
BoundColumn1 = CType(DataGridColumn1, BoundColumn)
BoundColumn1.HeaderText = "Custom\nHeader\nName"
Next

version 2:
Call
sub_FillDataSet(System.Configuration.ConfigurationSettings.AppSettings.Get("dbConnString"),
sbSQL.ToString, DataSet1)
DataView1 = DataSet1.Tables(0).DefaultView
Dim BoundColumn1 As BoundColumn
For Each BoundColumn1 In DataGrid1.Columns
BoundColumn1.HeaderText = "Custom\nHeader\nName"
Next
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top