Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 4th, 2007, 07:44 PM
Authorized User
 
Join Date: Oct 2006
Posts: 39
Thanks: 0
Thanked 0 Times in 0 Posts
Default Getting column name/header of a datagrid

Hi,

I have a datagrid in my application with auto-generated columns. I was able to put/customize its column header by using the following code:

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
        If (e.Item.ItemType = ListItemType.Header) Then
            e.Item.Cells(0).Text = "Ref No."
            e.Item.Cells(1).Text = "Implementation Tasks"


However, for the next column, I need to get the column/header name of the next columns. I need to add something to the column header based on its name.

Does anyone has an idea how to get the column names of a datagrid? Thanks in advance.

 
Old June 5th, 2007, 01:31 AM
Friend of Wrox
 
Join Date: Aug 2004
Posts: 550
Thanks: 0
Thanked 1 Time in 1 Post
Default

Well I am not sure what you are trying to say, you yourself set the header text, now you are asking how to find the column name of grid???? Then what does e.Item.Cells(0).Text do?? It will give u the column name of the 0th cell....


Regards
Mike

Don't expect too much, too soon.
 
Old June 6th, 2007, 01:07 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmmm. this seems pointless to me. Since you are binding to a datasource and have set your grid up to autogenerate, why not just manipulate the datasource?

Even if you can't do it in SQL you can do something like:

For Each dc as DataColumn in DataTable.Columns
    dc.Capation = "Foo"
Next

Of course you could set up a Select statement to deal with the different captions you will have but that shouldnt be to hard.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Runtime Column Header Text vinod_yadav1919 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 November 29th, 2008 01:53 AM
DataGridView's Column header apperance saravanan_article C# 2005 0 November 2nd, 2006 11:44 PM
Freezing Column and Header in DataGrid Control pramesh_it ASP.NET 1.0 and 1.1 Basics 0 April 3rd, 2006 05:54 AM
Fixing header, and first column of table. rupen CSS Cascading Style Sheets 5 October 21st, 2005 08:33 AM
Column Header jamol BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 December 23rd, 2004 05:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.