[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.aspnet.buildingcontrols

Setting DataFormatString on a textbox

TS

2/5/2009 5:29:00 PM

Hello, my project has a custom GridView control (inherited from GridView)
that uses TemplateFields to dynamically add controls based on meta data.
Since they aren't BoundFields I am now having to set DataFormatString on
each individual control but some controls dont have this option. For
DropDownList (and other ListControls) I have DataTextFormatString, but for
textbox and Label, etc i dont know how to set the format string.

for example, i have a textbox that when shown in read mode should show only
the date component of a datetime, so i want to do something like this
{0:MM/dd/yyyy} but dont know how


3 Answers

allenc

2/6/2009 1:38:00 AM

0

Hi TS,

From your description you have a TextBox in ItemTemplate of the GridView
that shows a date field and want to format the text, right? If so I think
you can try this:

Aspx:
<asp:TemplateField>
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%#DateFormat(Eval("theDate")) %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>

Aspx.cs:
protected string DateFormat(object input)
{
DateTime dt = DateTime.Parse(input.ToString());
string output = dt.ToString("MM/dd/yyyy");
return output;
}

Please have a try and let me know if it works.

Regards,
Allen Chen
Microsoft Online Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#not....

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa9...
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

allenc

2/10/2009 8:10:00 AM

0

Hi TS,

Have you tested my code? Can it work?

Regards,
Allen Chen
Microsoft Online Community Support

TS

2/13/2009 10:08:00 PM

0

thanks Allen, I found a different way to handle that in the binding method I
override in gridViewTemplate.

thanks!

"Allen Chen [MSFT]" <allenc@online.microsoft.com> wrote in message
news:p6rnCc1iJHA.5800@TK2MSFTNGHUB02.phx.gbl...
> Hi TS,
>
> Have you tested my code? Can it work?
>
> Regards,
> Allen Chen
> Microsoft Online Community Support
>