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

HeaderText & HeaderImageUrl in TemplateColumn in DataGrid

A DataGrid has the following TemplateColumn:

<asp:DataGrid ID="dgCart"...OnSortCommand="SortGrid"
AllowSorting="true"....>
<Column>
<asp:TemplateColumn HeaderImageUrl="Images\Up.gif" HeaderText="ID"
SortExpression="PID">
<ItemTemplate>
<asp:Label ID="lblPID" Text=<%# Container.DataItem("PID") %>
runat="server"/>
</ItemTemplate>
</TemplateColumn>
</Columns>
</asp:DataGrid>

It seems the HeaderImageUrl is given precedence over the HeaderText
since the Header just displays the image & not the text. How do I
display both HeaderText & HeaderImageUrl together?

The DataGrid allows sorting & by default, the DataGrid is sorted
ascendingly on the above column. When a user clicks the header Label
again, the column gets sorted descendingly....so far so good but I did
like to change the HeaderImageUrl at the same time so that users can
easily make out whether a column is sorted ascendingly or
descendingly.

Can someone please give me some idea on how do I go about it?

Mar 12 '07 #1
3 7358
Rather than placing the information as a property of the TemplateColumn,
try breaking it out:

<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<img src="Images\up.gif"><br/>
<div style="text-align:center; font-weight: bold">ID</div>
</HeaderTemplate>
<ItemTemplate>

....
</ItemTemplate>
....
</Columns>
-dl

---
David Longnecker
Web Developer
http://blog.tiredstudent.com
A DataGrid has the following TemplateColumn:

<asp:DataGrid ID="dgCart"...OnSortCommand="SortGrid"
AllowSorting="true"....>
<Column>
<asp:TemplateColumn HeaderImageUrl="Images\Up.gif" HeaderText="ID"
SortExpression="PID">
<ItemTemplate>
<asp:Label ID="lblPID" Text=<%# Container.DataItem("PID") %>
runat="server"/>
</ItemTemplate>
</TemplateColumn>
</Columns>
</asp:DataGrid>
It seems the HeaderImageUrl is given precedence over the HeaderText
since the Header just displays the image & not the text. How do I
display both HeaderText & HeaderImageUrl together?

The DataGrid allows sorting & by default, the DataGrid is sorted
ascendingly on the above column. When a user clicks the header Label
again, the column gets sorted descendingly....so far so good but I did
like to change the HeaderImageUrl at the same time so that users can
easily make out whether a column is sorted ascendingly or
descendingly.

Can someone please give me some idea on how do I go about it?


Mar 12 '07 #2
On Mar 12, 9:08 pm, David Longnecker <dlongnec...@community.nospam>
wrote:
Rather than placing the information as a property of the TemplateColumn,
try breaking it out:

<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<img src="Images\up.gif"><br/>
<div style="text-align:center; font-weight: bold">ID</div>
</HeaderTemplate>
<ItemTemplate>

...
</ItemTemplate>
...
</Columns>

-dl

---
David Longnecker
Web Developerhttp://blog.tiredstudent.com
A DataGrid has the following TemplateColumn:
<asp:DataGrid ID="dgCart"...OnSortCommand="SortGrid"
AllowSorting="true"....>
<Column>
<asp:TemplateColumn HeaderImageUrl="Images\Up.gif" HeaderText="ID"
SortExpression="PID">
<ItemTemplate>
<asp:Label ID="lblPID" Text=<%# Container.DataItem("PID") %>
runat="server"/>
</ItemTemplate>
</TemplateColumn>
</Columns>
</asp:DataGrid>
It seems the HeaderImageUrl is given precedence over the HeaderText
since the Header just displays the image & not the text. How do I
display both HeaderText & HeaderImageUrl together?
The DataGrid allows sorting & by default, the DataGrid is sorted
ascendingly on the above column. When a user clicks the header Label
again, the column gets sorted descendingly....so far so good but I did
like to change the HeaderImageUrl at the same time so that users can
easily make out whether a column is sorted ascendingly or
descendingly.
Can someone please give me some idea on how do I go about it?- Hide quoted text -

- Show quoted text -
Thanks for the solution David but there's a drawback. Note that I have
set the AllowSorting property of the DataGrid to true but you can't
use SortExpression while using a TemplateColumn column type with the
HeaderTemplate property set.

If I have to do it in the way you have suggested, then I will have to
use some control (like Button or LinkButton) within the HeaderTemplate
to make the DataGrid sortable. This has been documented in the .NET
Framework documentation as well (under the 'Remarks' section in ms-
help://MS.NETFramework.v20.en/cpref16/html/P_System_Web_UI_WebControls_DataGrid_AllowSorting. htm).

But then I don't think there is an alternate approach other than using
a control within the HeaderTemplate in the TemplateColumn column type
if I want both text as well as image in the headers & at the same time
render the DataGrid sortable.

Mar 14 '07 #3
On 14 mar, 07:21, r...@rediffmail.com wrote:
On Mar 12, 9:08 pm, David Longnecker <dlongnec...@community.nospam>
wrote:


Rather than placing the information as a property of the TemplateColumn,
try breaking it out:
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<img src="Images\up.gif"><br/>
<div style="text-align:center; font-weight: bold">ID</div>
</HeaderTemplate>
<ItemTemplate>
...
</ItemTemplate>
...
</Columns>
-dl
---
David Longnecker
Web Developerhttp://blog.tiredstudent.com
A DataGrid has the following TemplateColumn:
<asp:DataGrid ID="dgCart"...OnSortCommand="SortGrid"
AllowSorting="true"....>
<Column>
<asp:TemplateColumnHeaderImageUrl="Images\Up.gif"H eaderText="ID"
SortExpression="PID">
<ItemTemplate>
<asp:Label ID="lblPID" Text=<%# Container.DataItem("PID") %>
runat="server"/>
</ItemTemplate>
</TemplateColumn>
</Columns>
</asp:DataGrid>
It seems theHeaderImageUrlis given precedence over theHeaderText
since the Header just displays the image & not the text. How do I
display bothHeaderText&HeaderImageUrltogether?
The DataGrid allows sorting & by default, the DataGrid is sorted
ascendingly on the above column. When a user clicks the header Label
again, the column gets sorted descendingly....so far so good but I did
like to change theHeaderImageUrlat the same time so that users can
easily make out whether a column is sorted ascendingly or
descendingly.
Can someone please give me some idea on how do I go about it?- Hide quoted text -
- Show quoted text -

Thanks for the solution David but there's a drawback. Note that I have
set the AllowSorting property of the DataGrid to true but you can't
use SortExpression while using a TemplateColumn column type with the
HeaderTemplate property set.

If I have to do it in the way you have suggested, then I will have to
use some control (like Button or LinkButton) within the HeaderTemplate
to make the DataGrid sortable. This has been documented in the .NET
Framework documentation as well (under the 'Remarks' section in ms-
help://MS.NETFramework.v20.en/cpref16/html/P_System_Web_UI_WebControls_Data*Grid_AllowSorting .htm).

But then I don't think there is an alternate approach other than using
a control within the HeaderTemplate in the TemplateColumn column type
if I want both text as well as image in the headers & at the same time
render the DataGrid sortable.- Masquer le texte des messages précédents -

- Afficher le texte des messages précédents -
Hi,

You can add the img tag in the HeaderText property programmatically :
dgCart.Columns.Item(1).HeaderText = "<img src=""Images\Up.gif""
border=""0"">" & "ID"

regards,

David Fassi

Apr 27 '07 #4

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

Similar topics

1
by: John Wilson | last post by:
I am still working away to get to grips with .NET web forms. Can anyone help me with these conundrums? How do I programmatically control the with of a datagrid itself and the columns in it? At...
0
by: Steve R | last post by:
I have a Datagrid with several TemplateColumns. I am creating ALL (BoundColumn & TemplateColumn) of the columns for the DataGrid during the PAGE_INIT. One TemplateColumn is a checkbox that allows...
1
by: Manny Chohan | last post by:
Hi guys, i have the following code in Datagrid: <asp:TemplateColumn HeaderText="Delete" headerImageUrl=../../Images/i.p.delete.gif"> <ItemTemplate> <asp:CheckBox ID=Chk1 Enabled="True"...
1
by: Patrick Olurotimi Ige | last post by:
I want to add a HeaderText="Subject" and HeaderImageUrl="" to a Datagrid but it seems it doesn't work! It seems If i specify both header text and a header image, the header image takes...
1
by: andrewcw | last post by:
Where is the font size and type set for DataGrid in WINFORM. Thanks ( DataGridTableStyle ? or the DataGrid ? Its in the property page - but can it be set programmatically ? How ? Thanks
1
by: Arpan | last post by:
The output of a DataGrid is nothing but a HTML table. To color or change the width of the outer 4 borders of a DataGrid, one can use the properties "BorderColor" & "BorderWidth" respectively but...
0
by: arunpandey | last post by:
Friends I am creating columns and edit button in ASP.NET DataGrid at Run Time but when I click on the Edit Button disappears all columns and edit button itself. Only one column remains stay back,...
6
by: Neelesh2007 | last post by:
Hi to all. I m having project with VB6.0 as front End and Access-2003 as backend. In one of my code I m having Datagrid with ADODC as datasource. I want Drag & Drop Functionality in Datagrid as like...
4
akashazad
by: akashazad | last post by:
Dear Friends In my Project I want to Drag the text of the Text Box into any Particular cell of the DataGrid which ever user wants to, but my problem is I am not able to find the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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.