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

DataGrid header span 2 columns

I have a datagrid where each column has both a label and a linkbutton.

I need to have the label left justified and the linkbutton right justified.
In HTML, I would have to set up 2 cells to do this.

Is there a way to accomplish this in a DataGrid (and have the text span both
columns).

What I have is:

<asp:TemplateColumn Visible="true" headerText="Bundle(10):"
ItemStyle-Width="100" ItemStyle-VerticalAlign="Top">
<itemtemplate>
<asp:Label ID="Bundle10" text='<%#
String.Format("{0:$#,##0}",Container.DataItem("Bun dle(10)"))%>'
runat="server"/>
<asp:linkButton ID="Bundle10Link" text='Buy' runat="server"/>
</itemtemplate>
</asp:TemplateColumn>

I could make this into 2 TemplateColumns and but the HeaderText would only
be over the 1st column. There is no Header-Colspan attribute.

I also tried to have 2 itemTemplates inside the TemplateColumn, but I guess
you can't do that, as when I tried it, it only showed the 2nd itemTemplate.

Thanks,

Tom
Nov 19 '05 #1
6 2178
"tshad" <ts**********@ftsolutions.com> wrote in
news:uM**************@TK2MSFTNGP09.phx.gbl:
I have a datagrid where each column has both a label and a linkbutton.

I need to have the label left justified and the linkbutton right
justified. In HTML, I would have to set up 2 cells to do this.

Is there a way to accomplish this in a DataGrid (and have the text
span both columns).


You do this type of formatting in the OnItemDataBound Event.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 19 '05 #2
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@127.0.0.1...
"tshad" <ts**********@ftsolutions.com> wrote in
news:uM**************@TK2MSFTNGP09.phx.gbl:
I have a datagrid where each column has both a label and a linkbutton.

I need to have the label left justified and the linkbutton right
justified. In HTML, I would have to set up 2 cells to do this.

Is there a way to accomplish this in a DataGrid (and have the text
span both columns).
You do this type of formatting in the OnItemDataBound Event.


But that is my problem.

How would I do it?

If it puts the label and linkbutton in the same cell, how do you tell it to
align 1 left and 1 right?

Or if you use 2 templateColumns, how do you tell the header to span 2
columns?

Thanks,

Tom
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 19 '05 #3
"tshad" <ts**********@ftsolutions.com> wrote in
news:et**************@tk2msftngp13.phx.gbl:
If it puts the label and linkbutton in the same cell, how do you tell
it to align 1 left and 1 right?


You'll need to use CSS to align 2 items with 2 different alignments in the
same cell.

Otherwise use 2 cells (columns).

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 19 '05 #4
"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn***************************@127.0.0.1...
"tshad" <ts**********@ftsolutions.com> wrote in
news:et**************@tk2msftngp13.phx.gbl:
If it puts the label and linkbutton in the same cell, how do you tell
it to align 1 left and 1 right?
You'll need to use CSS to align 2 items with 2 different alignments in the
same cell.


I tried that:

Here is the template Column:

<asp:TemplateColumn Visible="true" headerText="Bundle(10):"
ItemStyle-Width="90" ItemStyle-VerticalAlign="Top">
<itemtemplate>
<asp:Label ID="Bundle10ID" visible="false" text='<%#
Container.DataItem("Bundle(10)ID")%>' runat="server"/>
<asp:Label ID="Bundle10" CssClass="onleft" text='<%#
String.Format("{0:$#,##0}",Container.DataItem("Bun dle(10)"))%>'
runat="server"/>
<asp:linkButton ID="Bundle10Link" CssClass="onright"
OnClick="GetPrice" text='Buy' runat="server"/>
</itemtemplate>

Here is the CSS:

..onright {text-align:right}
..onleft {text-align:left}
Here is the output:

<td valign="Top" style="width:90px;">
<span id="JobPostingGrid__ctl3_Bundle10"
class="onleft">$1,400</span>
<a id="JobPostingGrid__ctl3_Bundle10Link" class="onright"
href="javascript:__doPostBack('JobPostingGrid$_ctl 3$Bundle10Link','')">Buy</a>
</td>

But it just puts the 2 objects next to each other.

Am I using the wrong CSS?

Otherwise use 2 cells (columns).
Problem is the Header.
Thanks,

Tom
--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 19 '05 #5
read this - it might help

http://www.codeproject.com/aspnet/Me...gridHeader.asp

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"tshad" <ts**********@ftsolutions.com> wrote in message
news:uM**************@TK2MSFTNGP09.phx.gbl...
I have a datagrid where each column has both a label and a linkbutton.

I need to have the label left justified and the linkbutton right
justified. In HTML, I would have to set up 2 cells to do this.

Is there a way to accomplish this in a DataGrid (and have the text span
both columns).

What I have is:

<asp:TemplateColumn Visible="true" headerText="Bundle(10):"
ItemStyle-Width="100" ItemStyle-VerticalAlign="Top">
<itemtemplate>
<asp:Label ID="Bundle10" text='<%#
String.Format("{0:$#,##0}",Container.DataItem("Bun dle(10)"))%>'
runat="server"/>
<asp:linkButton ID="Bundle10Link" text='Buy' runat="server"/>
</itemtemplate>
</asp:TemplateColumn>

I could make this into 2 TemplateColumns and but the HeaderText would only
be over the 1st column. There is no Header-Colspan attribute.

I also tried to have 2 itemTemplates inside the TemplateColumn, but I
guess you can't do that, as when I tried it, it only showed the 2nd
itemTemplate.

Thanks,

Tom

Nov 19 '05 #6
"John Timney (ASP.NET MVP)" <ti*****@despammed.com> wrote in message
news:eC**************@TK2MSFTNGP09.phx.gbl...
read this - it might help

http://www.codeproject.com/aspnet/Me...gridHeader.asp
That's great.

I didn't know you could muck around with the headers like that.

The way I was going to solve it was to create a separate table just for the
header (which also works), but this is definately a more elegant method.

Solves the problem.

Thanks,

Tom
--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"tshad" <ts**********@ftsolutions.com> wrote in message
news:uM**************@TK2MSFTNGP09.phx.gbl...
I have a datagrid where each column has both a label and a linkbutton.

I need to have the label left justified and the linkbutton right
justified. In HTML, I would have to set up 2 cells to do this.

Is there a way to accomplish this in a DataGrid (and have the text span
both columns).

What I have is:

<asp:TemplateColumn Visible="true" headerText="Bundle(10):"
ItemStyle-Width="100" ItemStyle-VerticalAlign="Top">
<itemtemplate>
<asp:Label ID="Bundle10" text='<%#
String.Format("{0:$#,##0}",Container.DataItem("Bun dle(10)"))%>'
runat="server"/>
<asp:linkButton ID="Bundle10Link" text='Buy' runat="server"/>
</itemtemplate>
</asp:TemplateColumn>

I could make this into 2 TemplateColumns and but the HeaderText would
only be over the 1st column. There is no Header-Colspan attribute.

I also tried to have 2 itemTemplates inside the TemplateColumn, but I
guess you can't do that, as when I tried it, it only showed the 2nd
itemTemplate.

Thanks,

Tom


Nov 19 '05 #7

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

Similar topics

7
by: Billy Jacobs | last post by:
I am using a datagrid to display some data. I need to create 2 header rows for this grid with columns of varying spans. In html it would be the following. <Table> <tr> <td colspan=8>Official...
10
by: Alan Lambert | last post by:
I am writing a web-based reporting tool and using a datagrid to display information returned from a database. I am displaying column headings from bound columns with no problems but I need to...
8
by: Alejandro Penate-Diaz | last post by:
I have a datagrid inside a table and I want to fix both (table and databrid) width to 700, but when the content of datagrid is too large the width increases automatically sometimes and sometimes...
1
by: sri_san | last post by:
Hello, I have a datagrid in which the header needs to span over 2 columns. I have tried creating a tableCells and tableRow at runtime and set the columnspan property of a cell to 2. But, the...
1
by: Olav Tollefsen | last post by:
Is it possible to create a DataGrid footer to span multiple columns? Olav
4
by: Mortar | last post by:
i need a datagrid with 2 header columns. The top one might have 1 column spanning 5 columns of the header row below it. what is the best way to do this? Could i have 2 datatables...1 filling the...
1
by: Dave | last post by:
Hi, I'm trying to use templated columns to format the header for my datagrid. Can I use the HeaderTemplate to make the "My Title Goes.." text to span across the entire datagrid table when it's...
2
by: Mike Baugh | last post by:
I am using visual studio 2005 to develop a form using c# I have 3 datagrids on one form. I can set the row color based on a certain value in a column. However this color applies to all 3...
5
by: tshad | last post by:
I have a datagrid that I cannot get to right justify a money amount (which is just a label). No matter what I do - it still right justifies it. <asp:TemplateColumn Visible="true"...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.