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

formatting a data bound item

Status
Not open for further replies.

jgillin

Programmer
Oct 22, 2003
82
US
I'm trying to format one of the output values within a <asp:Repeater> control.
Basically, if the value output from the database equals 1000, I want to output &quot;N/A&quot; instead of &quot;1000&quot;. Code is below:
....
<%# DataBinder.Eval(Container.DataItem,&quot;MinMonthsSinceBankruptcy&quot;)%>

Is this possible using the repeater? Would the code have to be in the T-SQL statement or is is possible to have this code be passed as an argument to a function (that's implemented in the code-behind), such as :
<%# FormatBankruptcy(DataBinder.Eval(Container.DataItem,&quot;MinMonthsSinceBankruptcy&quot;))%>

Thanks for any thoughts and suggestions.
 
You can create a public method in the code behind to format your output:
Code:
in Repeater:
<%# FormatBankruptcy(DataBinder.Eval(Container.DataItem,&quot;MinMonthsSinceBankruptcy&quot;))%>
...

in code behind:
public string FormatBankruptcy(int minMonthSince)
{
  string caption = &quot;N/A&quot;;
  if(minMonthSince != 1000){
    caption = minMonthSince.ToString();
  }

  return caption;
}
 
Actually, the above line should be
Code:
<%# FormatBankruptcy(Convert.ToInt32(DataBinder.Eval(Container.DataItem,&quot;MinMonthsSinceBankruptcy&quot;)))%>
since
Code:
DataBinder.Eval(object, string)
returns an object.

regards,
Blaxo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top