473,606 Members | 2,101 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

HeaderText & HeaderImageUrl in TemplateColumn in DataGrid

A DataGrid has the following TemplateColumn:

<asp:DataGrid ID="dgCart"...O nSortCommand="S ortGrid"
AllowSorting="t rue"....>
<Column>
<asp:TemplateCo lumn HeaderImageUrl= "Images\Up. gif" HeaderText="ID"
SortExpression= "PID">
<ItemTemplate >
<asp:Label ID="lblPID" Text=<%# Container.DataI tem("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 7374
Rather than placing the information as a property of the TemplateColumn,
try breaking it out:

<Columns>
<asp:TemplateCo lumn>
<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"...O nSortCommand="S ortGrid"
AllowSorting="t rue"....>
<Column>
<asp:TemplateCo lumn HeaderImageUrl= "Images\Up. gif" HeaderText="ID"
SortExpression= "PID">
<ItemTemplate >
<asp:Label ID="lblPID" Text=<%# Container.DataI tem("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...@co mmunity.nospam>
wrote:
Rather than placing the information as a property of the TemplateColumn,
try breaking it out:

<Columns>
<asp:TemplateCo lumn>
<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.tiredstude nt.com
A DataGrid has the following TemplateColumn:
<asp:DataGrid ID="dgCart"...O nSortCommand="S ortGrid"
AllowSorting="t rue"....>
<Column>
<asp:TemplateCo lumn HeaderImageUrl= "Images\Up. gif" HeaderText="ID"
SortExpression= "PID">
<ItemTemplate >
<asp:Label ID="lblPID" Text=<%# Container.DataI tem("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_Da taGrid_AllowSor ting.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...@co mmunity.nospam>
wrote:


Rather than placing the information as a property of the TemplateColumn,
try breaking it out:
<Columns>
<asp:TemplateCo lumn>
<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.tiredstude nt.com
A DataGrid has the following TemplateColumn:
<asp:DataGrid ID="dgCart"...O nSortCommand="S ortGrid"
AllowSorting="t rue"....>
<Column>
<asp:TemplateCo lumnHeaderImage Url="Images\Up. gif"HeaderText= "ID"
SortExpression= "PID">
<ItemTemplate >
<asp:Label ID="lblPID" Text=<%# Container.DataI tem("PID") %>
runat="server"/>
</ItemTemplate>
</TemplateColumn>
</Columns>
</asp:DataGrid>
It seems theHeaderImageU rlis given precedence over theHeaderText
since the Header just displays the image & not the text. How do I
display bothHeaderText& HeaderImageUrlt ogether?
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 theHeaderImageU rlat 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_Da ta*Grid_AllowSo rting.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 programmaticall y :
dgCart.Columns. Item(1).HeaderT ext = "<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
1298
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 the moment my grid is wider than the columns, leaving a spare bit to the right, and yet some of my columns are too narrow. Can I even get them to adjust automatically, eg to the width of the widest cell value? Also, how do I get numeric data to...
0
992
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 the user to select the row/datagriditem to carry forward in a wizard. The other TemplateColumns contain a System.Web.UI.WebControls.Image. In the ITEMCREATED event for the datagrid, I toggle the ImageURL property for each Image based on certain...
1
1518
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" runat="server" /> </ItemTemplate> </asp:TemplateColumn> when i run the page, i get the following error:
1
1634
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 precedence!!! Any ideas how i could dislpay both at the same time Sample below!! <Columns> <%-- Manipulate the subject entry so that it contains a link to the reply page --%> <asp:TemplateColumn HeaderText="Subject"
1
1445
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
2173
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 how does one change the border color & width of the 4 borders surrounding each cell? There are 4 other properties apparently meant for changing the border color & width of the 4 borders surrounding each cell i.e. HeaderStyle-BorderColor &...
0
1129
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, which I have defined in HTML Page. Codes for Dynamically generating columns, I have written at Page_Load Event. Please Give me your suggestions that where to write these code to generate Dynamic Columns at Run Time. Thanks in Advance.
6
4208
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 in Excel so that I can paste value in to other rows just by drag & Drop. Is it possible? Thanks.
4
5654
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 Coordinates of the cell cell in which user will drop the text and hence not able to put the text into desired Cell. Code snippet below shows the code in the Dragdrop event of the dataGrid Dim sText As String = "" Dim nrow As Integer = 'Need...
0
8433
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8429
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8300
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6761
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5963
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5461
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3922
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3969
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1550
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.