Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataGrid header span 2 columns

Reply
Thread Tools

DataGrid header span 2 columns

 
 
tshad
Guest
Posts: n/a
 
      08-22-2005
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


 
Reply With Quote
 
 
 
 
Lucas Tam
Guest
Posts: n/a
 
      08-22-2005
"tshad" <> wrote in
news::

> 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 ()
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
 
Reply With Quote
 
 
 
 
tshad
Guest
Posts: n/a
 
      08-22-2005
"Lucas Tam" <> wrote in message
news:Xns96BA85D75B70Fnntprogerscom@127.0.0.1...
> "tshad" <> wrote in
> news::
>
>> 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 ()
> Please delete "REMOVE" from the e-mail address when replying.
> http://members.ebay.com/aboutme/coolspot18/



 
Reply With Quote
 
Lucas Tam
Guest
Posts: n/a
 
      08-22-2005
"tshad" <> wrote in
news::

> 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 ()
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
 
Reply With Quote
 
tshad
Guest
Posts: n/a
 
      08-22-2005
"Lucas Tam" <> wrote in message
news:Xns96BA9DC94D66Enntprogerscom@127.0.0.1...
> "tshad" <> wrote in
> news::
>
>> 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 ()
> Please delete "REMOVE" from the e-mail address when replying.
> http://members.ebay.com/aboutme/coolspot18/



 
Reply With Quote
 
John Timney \(ASP.NET MVP\)
Guest
Posts: n/a
 
      08-22-2005
read this - it might help

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

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"tshad" <> wrote in message
news:...
>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
>



 
Reply With Quote
 
tshad
Guest
Posts: n/a
 
      08-22-2005
"John Timney (ASP.NET MVP)" <> wrote in message
news:...
> 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" <> wrote in message
> news:...
>>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
>>

>
>



 
Reply With Quote
 
nak nak is offline
Junior Member
Join Date: May 2012
Location: Ohio
Posts: 1
 
      05-04-2012
Quote:
Originally Posted by tshad View Post
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).
[snip]

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
"There is no Header-Colspan attribute."
Not at design time. You can get to it later.

Use 2 columns and catch the ItemDataBound event for the grid. The code below gets rid of the third columnof the header and expands the second one to cover it.


PrivateSub MyGrid_ItemDataBound(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles MyGrid.ItemDataBound

If e.Item.ItemType = ListItemType.Header Then
'remove the third cell and make the second cell cover it
e.Item.Cells.RemoveAt(2)
e.Item.Cells(1).ColumnSpan = 2
Return

End If
End Sub
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can span include span? Fulio Open HTML 5 06-26-2009 10:24 PM
datagrid field to span other columns? JeffP@Work ASP .Net Datagrid Control 1 10-20-2006 08:46 AM
DataGrid footer to span columns? Olav Tollefsen ASP .Net 1 01-31-2005 09:16 AM
datagrid - Header span over multiple columns sri_san@mailcity.com ASP .Net 1 01-26-2005 05:59 PM
DataGrid (body only) contained in <span>...</span> tags Dan Bishop ASP .Net Datagrid Control 2 06-07-2004 04:00 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57