473,387 Members | 1,585 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,387 software developers and data experts.

dyanmaically name column in datagrid

I'm trying to set a column name when my datagrid is being rendered. I've
used the OnItemDataBound event before, so I decided to try and use it again
here.
The problem I'm having is I'm trying to test for a DataColumn from the bound
source with a name of "Info" and I'm not sure how to do that. Here's what
I've been trying:

Sub GuestGrid_OnItemDataBound(ByVal source As Object, ByVal e As
DataGridItemEventArgs)

'only bother header items

If (e.Item.ItemType = ListItemType.Header) Then

'Set the variable Info column heading text

If Not IsNothing(Trim(e.Item.DataItem("Info"))) Then

e.Item.Cells.Item(0).Text = "testing"

End If

End If

End Sub

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

The part I'm having trouble with is that If Not
IsNothing(Trim(e.Item.DataItem("Info"))) part. That errors out. How can I
detirmine if there is a column with the name "Info"? Thanks!

Matt
Nov 18 '05 #1
2 1094
You'd Use OnItemDataBound if you're working with the items (rows).
To work with the Columns, you just have to say something like
MyGrid.Columns(0).TeaderText="HeyThere!"

"MattB" <so********@yahoo.com> wrote in message
news:2g***********@uni-berlin.de...
I'm trying to set a column name when my datagrid is being rendered. I've
used the OnItemDataBound event before, so I decided to try and use it again here.
The problem I'm having is I'm trying to test for a DataColumn from the bound source with a name of "Info" and I'm not sure how to do that. Here's what
I've been trying:

Sub GuestGrid_OnItemDataBound(ByVal source As Object, ByVal e As
DataGridItemEventArgs)

'only bother header items

If (e.Item.ItemType = ListItemType.Header) Then

'Set the variable Info column heading text

If Not IsNothing(Trim(e.Item.DataItem("Info"))) Then

e.Item.Cells.Item(0).Text = "testing"

End If

End If

End Sub

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

The part I'm having trouble with is that If Not
IsNothing(Trim(e.Item.DataItem("Info"))) part. That errors out. How can I
detirmine if there is a column with the name "Info"? Thanks!

Matt

Nov 18 '05 #2
That's pretty much what I'm doing, but I was hoping I could base the column
selection on the name of the dataColumn instead of the metric. Looks like I
can't.

Thanks for the reply...

Matt

David Jessee wrote:
You'd Use OnItemDataBound if you're working with the items (rows).
To work with the Columns, you just have to say something like
MyGrid.Columns(0).TeaderText="HeyThere!"

"MattB" <so********@yahoo.com> wrote in message
news:2g***********@uni-berlin.de...
I'm trying to set a column name when my datagrid is being rendered.
I've used the OnItemDataBound event before, so I decided to try and
use it again here.
The problem I'm having is I'm trying to test for a DataColumn from
the bound source with a name of "Info" and I'm not sure how to do
that. Here's what I've been trying:

Sub GuestGrid_OnItemDataBound(ByVal source As Object, ByVal e As
DataGridItemEventArgs)

'only bother header items

If (e.Item.ItemType = ListItemType.Header) Then

'Set the variable Info column heading text

If Not IsNothing(Trim(e.Item.DataItem("Info"))) Then

e.Item.Cells.Item(0).Text = "testing"

End If

End If

End Sub

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

The part I'm having trouble with is that If Not
IsNothing(Trim(e.Item.DataItem("Info"))) part. That errors out. How
can I detirmine if there is a column with the name "Info"? Thanks!

Matt


Nov 18 '05 #3

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

Similar topics

3
by: AFN | last post by:
In VB.NET, I can successfully bind a generic datagrid to a 1 dimensional array. But, now I want to add a button column, and so I think I need to make the first column (the one having data in the...
4
by: JIM.H. | last post by:
Hello, string colVal =((TextBox)e.Item.Cells.Controls).Text; this is how I reach column value in a grid: how can I reach with the column name? some value should be int, some date, how should I...
5
by: HS1 | last post by:
Hello I have a datagrid to show data for a database table using "seclect * from tablename" The datagrid works OK. However, I want to change the name of the fields in the database to other...
1
by: nate axtell | last post by:
In VB .NET I load the contents of an Excel or comma seperated values file into a dataGrid (via a datatable). One of the columns has a comma in the name of the column. So for the comma separated...
3
by: serge calderara | last post by:
Dear all, I have a datagrid erver control which is bind to a dataset. How to display as column name custom text instead of database fields name ? Ex : Started At instead of START_TIME_COL ...
7
by: Mark B | last post by:
Can someone write some VB.Net example code for me that does this: 1) Creates a gridview control with the results of a SQL stored procedure that has 1 parameter (text) 2) Adds an extra column...
1
by: Brock | last post by:
First note that I am using Framework 1.1. I have an .aspx page that is displaying a list of employees, but only the Employee Number, First Name, Last Name, and Title. It is working great. I...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
2
by: =?Utf-8?B?Y3JlYXZlczA2MjI=?= | last post by:
I have a nested datagrid in a xaml file, the parent datagrid loads the vendor information and the details loads the documents for that vendor in a datagrid. Everything is working fine until I click...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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.