Solved

Change HeaderText of DataGrid

Posted on 2004-10-01
1
1,226 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
Comment Utility
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now