DataFormatString questions...

M

Michael Tanner

I have 2 formatting cases that I need to handle:

Case 1: an eight digit account number stored in database as such - 12345678
I need to display this in a boundcolumn as such - 1234-5678

Case 2: a number is stored in the database as such - 42
I need to display this in a boundcolumn as such - 0000042

Can I use the DataFormatString property to accomplish these 2 cases and how?

Thanks,
Mike
 
A

Aaron Weiker

Mike,
Here is a brief sample that you can put into an ASP.NET page and it will
demonstrate on how to do what you wanted. For more information look up
String.Format() in the MSDN library.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/htm
l/frlrfsystemstringclassformattopic2.asp

<!-- ################################# -->

<%@ Page Language="C#" Debug="True" %>
<script runat="server">
private void Page_Load(object sender, EventArgs e) {
if (original.Text.Length > 0) {
result1.Text = String.Format("{0:000000##}", int.Parse(original.Text));
result2.Text = String.Format("{0:0000-0000}", int.Parse(original.Text));
}

}
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:textbox id="original" runat="server" /> <br />
<asp:label id="result1" runat="server" /> <br />
<asp:label id="result2" runat="server" /> <br />
<asp:button id="transform" runat="server" text="transform" />
</form>
</body>
</html>
<!-- ################################# -->

Aaron Weiker
http://aaronweiker.com/posts/174.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top