Datagrid Right align problem (bug?)

samsmithnz

Senior Contributor
Joined
Jul 22, 2003
Messages
1,038
Location
Boston
I have a datagrid with a right aligned column like this:

Code:
<ASP:TEMPLATECOLUMN headertext="invoice_amount" sortexpression="invoice_amount" itemstyle-cssclass="datagrid">
	<HEADERSTYLE horizontalalign="Right"></HEADERSTYLE>
	<ITEMSTYLE width="80" horizontalalign="Right"></ITEMSTYLE>
	<HEADERTEMPLATE>
		<ASP:IMAGEBUTTON id="btnSortAmount1" runat="server" imageurl="images/mailbox_amount.gif" commandname="sort"
			commandargument="invoice_amount"></ASP:IMAGEBUTTON>
		<ASP:IMAGEBUTTON id="btnSortAmount2" runat="server" imageurl="images/mailbox_arrow_off.gif" commandname="sort"
			commandargument="invoice_amount"></ASP:IMAGEBUTTON>
	</HEADERTEMPLATE>
	<ITEMTEMPLATE>
		<A HREF='InvoiceDetails.aspx?InvoiceID=<%#DataBinder.Eval(Container.DataItem, "invoice_id")%>'><%# DataBinder.Eval(Container.DataItem, "invoice_amount","{0:#,###,##0.00}")%> <%# DataBinder.Eval(Container.DataItem, "invoice_currency_code")%></A>
	</ITEMTEMPLATE>
</ASP:TEMPLATECOLUMN>

But the data in the column seems to right align with an invisible margin (see attached screenshot). any ideas why???
 

Attachments

Thanks Rory, it was a nice theory, but when I add "t"'s to each side of the string:
Code:
<ITEMTEMPLATE>
    <%="t"%><%# DataBinder.Eval(Container.DataItem, "invoice_amount","{0:#,###,##0.00}")%><%="t"%>
</ITEMTEMPLATE>

I still get the trailing spaces... anyway the invoice_amount is of type money in the database, but this shows that trimming the data wouldn't help anyway......

hmmm now what...?
 

Attachments

I have it. Its the width property in the ITEMSTYLE. Instead of creating a column width, it seems to add a margin to the right side. Removing it fixes the problem (and creates others, but thats ok for now)
 
In the google forum... they told that it was the type of the string.
If your string is char then their will be space added to the end.
If you use varchar their wont be any unneeded spaces.

Hope this help too even if it was already "said".
 
An ItemTemplate column actually generates at least three controls (depending on what you put inside the <ItemTemplate> tags)

There's a Literal tag on the left and right of what you define...... anyways, the easy fix for alignment is to just add a <div> tag around your code:

Code:
<ITEMTEMPLATE>
       <div align="right">
		<A HREF='InvoiceDetails.aspx?InvoiceID=<%#DataBinder.Eval(Container.DataItem, "invoice_id")%>'><%# DataBinder.Eval(Container.DataItem, "invoice_amount","{0:#,###,##0.00}")%> <%# DataBinder.Eval(Container.DataItem, "invoice_currency_code")%></A>
      </div>
</ITEMTEMPLATE>

done
 
Back
Top