Click here to Skip to main content
16,022,417 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am using <%# %> for data binding in my aspx page. The values extracted are D, W & M.
Is it possible to rename the one character codes i.e. D to DAY, W to WEEK and M to MONTHLY?

ASPX code
XML
</asp:TemplateField><asp:TemplateField HeaderText="FREQUENCY:">
    <ItemTemplate>
        <asp:Label ID="lblFreq" runat="server" Text='<%# Eval("Frequency") %>' />
    </ItemTemplate>
</asp:TemplateField>


Thanx
Aj
Posted
Updated 21-Oct-10 9:50am
v2

Hi,

you can solve above issue by writing code in server side.

Call the below function in the Gridview rowdatabound event.

Label lbl=(Label)e.Row.FindControl("lblFreq");

if(lbl.Text=="D")
{
lbl.Text="Day";
}
else if(lbl.Text=="M")
{
lbl.Text="Month";
}
else
{
lbl.Text="Week";
}
 
Share this answer
 
XML
</asp:TemplateField><asp:TemplateField HeaderText="FREQUENCY:">
    <ItemTemplate>
        <asp:Label ID="lblFreq" runat="server" Text='<%# ChangeEval(Eval("Frequency")) %>' />
    </ItemTemplate>
</asp:TemplateField>


You can add custom binding for your control, now in aspx.cs page Implement ChangeEval

for example

public object ChangeEval(object evalValue)
{
  if(evalValue.Tostring()=="D")
     return "DAY";
  else if(....)
     return ...
....
}
 
Share this answer
 
Comments
Ankur\m/ 22-Oct-10 0:13am    
Correct!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900