开发者

Using variable for asp.net repeater eval

I am new to ASP.NET

Can I use variable in eval in repeater? Or h开发者_开发百科ow can I use it?

For example:

<%# DataBinder.Eval(Container.DataItem, lngHome) %>

Code behind in form load:

if (session["dilKod"] == "eng")
 {
   lngHome = "eng_detail"
 }
 else
{
   lngHome = "tr_detail"
}

I have 2 fields in database table: eng_detail and tr_detail

So how can I use like this <%# DataBinder.Eval(Container.DataItem, lngHome) %>?

Sorry for my poor English :)


Is lngHome a public property? Then you can just use:

<%# lngHome %>

Make sure you initialize lngHome with a default value or set it before databinding occurs. So move this to Page_init instead:

if (session["dilKod"] == "eng")
 {
   lngHome = "eng_detail"
 }
 else
{
   lngHome = "tr_detail"
}


Yes you can, lngHome should be public global field of the class, for example:

public partial class WebForm1 : System.Web.UI.Page
{
   public string lngHome  = "someDefaultValue";
   ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜