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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change Databinder.Eval expression during runtime

Status
Not open for further replies.

rockyprince

Programmer
Aug 11, 2004
4
GB
Hi all,

I have a datagrid like this:

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

<asp:Datagrid id="datagrid" runat="server" width="100%">
<Columns>
<asp:TemplateColumn HeaderText="Date">
<ItemTemplate>
<asp:Label Runat="server" ID="lblDate"><%# DataBinder.Eval(Container.DataItem,"Date","{0:D}")%></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:Datagrid>

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

Now, I also have two radio buttons, one to display the "Date" in US format, and the other to change it to UK format.

Is there a way I can change the 'DataBinder.Eval(...' expression in my code behind? to allow me to change the format character '{0:D}' to something else.

I have an alternative solution, where I use the following expression instead:

<%#getDate(DataBinder.Eval(Container.DataItem,"date").ToString())%>


...where getDate is a protected function, that formats the date depending on which radio button is checked.
This will work, but I was looking for something more pretty.

Thanks for any help,
Rocky

 
If you set your radio buttons to automatically post back, you could use FindControl to get a reference to the label, pass it's text to a function that will change the format, and then update the text to the new format.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 

Hi ca8msm, thanks for your reply.

the item in question is a column within a datagrid, if I use FindControl, it will be messy getting a handle on ALL the items on the datagrid that I need to reformat.

Maybe if I use the datagrid.ItemDataBound event, but I imagine it's no prettier than using the function call I've suggested in the original email.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top