Solved

Change HeaderText of DataGrid

Posted on 2004-10-01
1
1,230 Views
Last Modified: 2009-12-16
I want to change HeaderText of Datagrid. This is my solution
Here my code:
<asp:BoundColumn DataField="ProductID" SortExpression="ProductID" HeaderText="Product ID"></asp:BoundColumn>
<asp:BoundColumn DataField="ProductName" SortExpression="ProductName" HeaderText="<%# GetText() %>"></asp:BoundColumn>
<asp:BoundColumn DataField="QuantityPerUnit" SortExpression="QuantityPerUnit" HeaderText="Quantity Per Unit"></asp:BoundColumn>
----
private string GetText()
{
     return "Hello";
}

But I get Error:

CS0117: 'System.Web.UI.WebControls.BoundColumn' does not contain a definition for 'DataBinding'

Note: I don't want to use:
MyDataGrid.Columns[2].HeaderText="Hello";      

Thanks!
0
Comment
Question by:minhngvan
1 Comment
 
LVL 10

Accepted Solution

by:
123654789987 earned 125 total points
ID: 12215438
Since it a bound column u have to specify the DataField property of the Column.  If u are populating the Column from a DataTable then DataField is one of the columns of this dataTable. Howeveru can have a Column Header Text of your choice by using the HeaderText property.

See the following link on BoundColumns.

http://aspnet.4guysfromrolla.com/articles/072603-1.aspx
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/creatingcustomcolumns.asp
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Media.Imaging 1 24
compare between entities in entity framework 8 93
Can I command line build a C# application? 6 40
C# LINQ ForEach() question 6 54
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question