473,386 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

setting header text for a datagrid?

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.ConfigurationSe ttings.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()

Nov 19 '05 #1
1 1230
I added some code, and am getting an error "Specified cast is not
valid."

version 1:
Call
sub_FillDataSet(System.Configuration.Configuration Settings.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.Configuration Settings.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

Mad Scientist Jr wrote:
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.ConfigurationSe ttings.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()


Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Bruce Wolfe | last post by:
I have a datagrid and I need to programmatically set the height for each row based on the number of lines of text. I have my own column style subclassed from...
1
by: Webgour | last post by:
Hi, I'm tring to add a column to a datagrid with a linkbutton as header that can be used to sort the column. The column and the linkbutton are added programmatically (see below). However the...
3
by: AMD Desktop | last post by:
Hi, I need to add a header to a datagrid. This is the code I am trying to use: Dim dgStaffingReport As New DataGrid Dim dgitem As New DataGridItem(0, 0, ListItemType.Header) Dim mycell...
4
by: Adam Boczek | last post by:
I've a dropdownlist control to change language on my page. Because of page lifetime, I have to set all my labels, texts etc. from ResourceManager in prerender handler to be sure that culture change...
2
by: saleek | last post by:
I was wondering if there is a way I can add an extra header to a datagrid? I found this solution on the internet - but it seems quite old and didn't work for me. ...
1
by: Mad Scientist Jr | last post by:
i am trying to set the text of the row header in a datagrid i found several examples in all cases the TopRow() property is not recognized by VS.NET any help appreciated! VERSION 1 (based on...
2
by: Santosh | last post by:
Dear all i want to bind data to datagrid header template i am wrtting follwing code it is displaying data with in item template not but it is display data in header template <asp:DataGrid...
1
by: Santosh | last post by:
Dear all I am writting following code for binding data to the header template of the datagrid on the button click event. but it gives me an error object referance is not set to an item of object...
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.