Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Putting $ symbol into Datagrid

Status
Not open for further replies.

gi11ies

Programmer
Mar 26, 2002
52
Hi

I have a datagrid, and wish to put a $ symbol in beside the cost, has anyone any tips on how to do this?

My datagrid code is:

<asp:DataGrid id="scartdg" AutoGenerateColumns="false" runat="server">
<columns>
<asp:HyperLinkColumn HeaderText ="Product" DataTextField="Product" DataNavigateUrlField="ProductID" DataNavigateUrlFormatString="../products/item.aspx?id={0}"/>
<asp:boundcolumn HeaderText="Qty" HeaderStyle-HorizontalAlign="left" ItemStyle-HorizontalAlign="left" DataField="Quantity" />
<asp:boundcolumn HeaderText="Price (each)" HeaderStyle-HorizontalAlign="left" ItemStyle-HorizontalAlign="left" DataField="Cost" />
</columns>
</asp:DataGrid>

I'd like to put it along with:

<asp:boundcolumn HeaderText="Price (each)" HeaderStyle-HorizontalAlign="left" ItemStyle-HorizontalAlign="left" DataField="Cost" />

Any help would be great !!!!

Gillies
 
There are lots of ways of doing it. You could:

1) Return it in the SQL
2) Add it in the ItemDatBound event
3) Add another control with it in (e.g. a Literal)

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
yeah:
<asp:templatecolumn HeaderText="Price (each)" HeaderStyle-HorizontalAlign="left" ItemStyle-HorizontalAlign="left">
<itemtemplate>
$<%# DataBinder.Eval(Container.DataItems,"Cost") %>
</temtemplate>
</asp:templatecolumn>

Known is handfull, Unknown is worldfull
 
I would put it inside a Literal control though rather than just writing it as plain text in the HTML though (i.e. my third suggestion).

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
an e.g.?

Known is handfull, Unknown is worldfull
 
The easiest example would actually be in a Label so that it could be easily retrived. e.g.
Code:
<asp:Label id="lblCurrency" runat="server">$</asp:Label>


--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
i want an example with the control within ItemTemplate(My reference book doesnt have one)...

Known is handfull, Unknown is worldfull
 
Just copy the label code so it's within the itemtemplate tag...

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
oh, whats the advantage over simply typing text there???

Known is handfull, Unknown is worldfull
 
What if you wanted to change that currency value to a £ sign in code?

If you needed to do it and you used a label, you could use FindControl to get a reference to the label, and set the Text property to equal "£".

How would you change it if you had just written it like in your example?

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
oh ok. is there any performance benefits?

Known is handfull, Unknown is worldfull
 
That example uses a label like I suggested!

If you tried to update to a £ sign using your exmaple you couldn't do it (without a lot of work)!

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
yes it does, but i just pointed out the other approach ;)

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top