Connecting Tech Pros Worldwide Forums | Help | Site Map

DataGrid header span 2 columns

tshad
Guest
 
Posts: n/a
#1: Nov 19 '05
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



Lucas Tam
Guest
 
Posts: n/a
#2: Nov 19 '05

re: DataGrid header span 2 columns


"tshad" <tscheiderich@ftsolutions.com> wrote in
news:uMMaTrzpFHA.3340@TK2MSFTNGP09.phx.gbl:
[color=blue]
> 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).[/color]

You do this type of formatting in the OnItemDataBound Event.

--
Lucas Tam (REMOVEnntp@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
tshad
Guest
 
Posts: n/a
#3: Nov 19 '05

re: DataGrid header span 2 columns


"Lucas Tam" <REMOVEnntp@rogers.com> wrote in message
news:Xns96BA85D75B70Fnntprogerscom@127.0.0.1...[color=blue]
> "tshad" <tscheiderich@ftsolutions.com> wrote in
> news:uMMaTrzpFHA.3340@TK2MSFTNGP09.phx.gbl:
>[color=green]
>> 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).[/color]
>
> You do this type of formatting in the OnItemDataBound Event.[/color]

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[color=blue]
>
> --
> Lucas Tam (REMOVEnntp@rogers.com)
> Please delete "REMOVE" from the e-mail address when replying.
> http://members.ebay.com/aboutme/coolspot18/[/color]


Lucas Tam
Guest
 
Posts: n/a
#4: Nov 19 '05

re: DataGrid header span 2 columns


"tshad" <tscheiderich@ftsolutions.com> wrote in
news:eteblj0pFHA.2472@tk2msftngp13.phx.gbl:
[color=blue]
> If it puts the label and linkbutton in the same cell, how do you tell
> it to align 1 left and 1 right?[/color]

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 (REMOVEnntp@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
tshad
Guest
 
Posts: n/a
#5: Nov 19 '05

re: DataGrid header span 2 columns


"Lucas Tam" <REMOVEnntp@rogers.com> wrote in message
news:Xns96BA9DC94D66Enntprogerscom@127.0.0.1...[color=blue]
> "tshad" <tscheiderich@ftsolutions.com> wrote in
> news:eteblj0pFHA.2472@tk2msftngp13.phx.gbl:
>[color=green]
>> If it puts the label and linkbutton in the same cell, how do you tell
>> it to align 1 left and 1 right?[/color]
>
> You'll need to use CSS to align 2 items with 2 different alignments in the
> same cell.[/color]

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?
[color=blue]
>
> Otherwise use 2 cells (columns).[/color]

Problem is the Header.


Thanks,

Tom[color=blue]
>
> --
> Lucas Tam (REMOVEnntp@rogers.com)
> Please delete "REMOVE" from the e-mail address when replying.
> http://members.ebay.com/aboutme/coolspot18/[/color]


John Timney \(ASP.NET MVP\)
Guest
 
Posts: n/a
#6: Nov 19 '05

re: DataGrid header span 2 columns


read this - it might help

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

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"tshad" <tscheiderich@ftsolutions.com> wrote in message
news:uMMaTrzpFHA.3340@TK2MSFTNGP09.phx.gbl...[color=blue]
>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
>[/color]


tshad
Guest
 
Posts: n/a
#7: Nov 19 '05

re: DataGrid header span 2 columns


"John Timney (ASP.NET MVP)" <timneyj@despammed.com> wrote in message
news:eCwHwd2pFHA.3744@TK2MSFTNGP09.phx.gbl...[color=blue]
> read this - it might help
>
> http://www.codeproject.com/aspnet/Me...gridHeader.asp[/color]

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[color=blue]
>
> --
> Regards
>
> John Timney
> ASP.NET MVP
> Microsoft Regional Director
>
> "tshad" <tscheiderich@ftsolutions.com> wrote in message
> news:uMMaTrzpFHA.3340@TK2MSFTNGP09.phx.gbl...[color=green]
>>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
>>[/color]
>
>[/color]


Closed Thread