Solved

Change HeaderText of DataGrid

Posted on 2004-10-01
1
1,228 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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