在我的站点中,我定义了一个Dictionary,它根据会话返回Persian或English字符串。这是我的字典的代码:
public static string Find_Term(string term)
{
var dictionary = new Dictionary<string, string>();
dictionary.Add("Accommodation Barges", "بارج اقامتی");
dictionary.Add("Bulk Carriers", "فله بر");
dictionary.Add("Barge", "بارج");
dictionary.Add("Cable Layers", "کابل گذار");
dictionary.Add("Cargo Ships", "باربری");
dictionary.Add("Container Ships", "کانتینر بر");
dictionary.Add("Crew Boats", "پرسنل بر");
dictionary.Add("Cruise Ships", "کروز");
dictionary.Add("Dive Boats", "قایق قواصی");
dictionary.Add("Drilling Rigs", "سکوی حفاری");
dictionary.Add("Fishing Boat", "ماهیگیری");
dictionary.Add("Ferries", "فری");
dictionary.Add("Floating Cranes", "کرن شناور");
dictionary.Add("Floating Hotels", "هتل شناور");
dictionary.Add("Glass Bottom Boats", "کف شیشه ای");
dictionary.Add("Hovercraft", "هاورکرافت");
dictionary.Add("Hydrofoils", "Hydrofoils");
dictionary.Add("Ice Breakers", "یخ شکن");
dictionary.Add("Life Boats", "لایف بوت");
dictionary.Add("Landing Craft", "لندینگ کرافت");
dictionary.Add("Life Rafts", "لایف رافت");
dictionary.Add("Passenger Boats", "مسافر بر");
dictionary.Add("Patrol Boats", "گشت");
dictionary.Add("Pilot Boats", "پایلوت بوت");
dictionary.Add("Platforms", "پلتفرم");
dictionary.Add("Research Vessels", "تحقیقاتی");
dictionary.Add("Salvage Ships", "از رده خارج");
dictionary.Add("Supply Boats", "ساپلای بوت");
dictionary.Add("Support Vessels", "ساپورت بوت");
dictionary.Add("Tankers", "تانکر");
dictionary.Add("Tour Boats", "تور");
dictionary.Add("Towboats", "هدایت کننده");
dictionary.Add("Tugs", "یدک کش");
dictionary.Add("Utility Boats", "یوتیلیتی بوت");
dictionary.Add("All Types", "همه نوع");
dictionary.Add("LogIn", "ورود");
dictionary.Add("Register", "ثبت نام");
dictionary.Add("LogOut", "خروج");
dictionary.Add("Home", "صفحه اصلی");
dictionary.Add("News", "تازه ها");
//dictionary.Add("Builder", "سازنده");
dictionary.Add("Builder", "سازنده");
dictionary.Add("Request this vessel", "درخواست این شناور");
dictionary.Add("Ship Particular", "مشخصات شناور");
dictionary.Add("Build Year", "سال ساخت");
if (HttpContext.Current.Session["Lang"].ToString() == "fa")
{
return dictionary[term];
}
else
{
return term;
}
//
// TODO: Add constructor logic here
//
}返回的字符串用于网站中关键元素的文本属性。例如,如下所示,它可以很好地工作在中继器中的按钮上:
<asp:Repeater runat="server" ID="vslCat" DataSourceID="SqlDataSource2">
<ItemTemplate>
<asp:LinkButton runat="server" Text='<%# Dict.Find_Term(Eval("vCat").ToString()) %>' PostBackUrl='<%# Request.RawUrl + "?vslCat=" + Eval("vCat") %>' CssClass="ui-btn ui-mini ui-shadow ui-btn-icon-right ui-icon-carat-r"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater>但是在中继器外部的同一元素中,它没有返回任何错误!
<asp:LinkButton runat="server" Text='<%# Dict.Find_Term("All Types")%>' CssClass="ui-btn ui-mini ui-shadow ui-btn-icon-right ui-icon-carat-r" PostBackUrl="~/Default2.aspx" ID="btnCatAllen"></asp:LinkButton>
<asp:Repeater runat="server" ID="vslCat" DataSourceID="SqlDataSource2">
<ItemTemplate>
<asp:LinkButton runat="server" Text='<%# Dict.Find_Term(Eval("vCat").ToString()) %>' PostBackUrl='<%# Request.RawUrl + "?vslCat=" + Eval("vCat") %>' CssClass="ui-btn ui-mini ui-shadow ui-btn-icon-right ui-icon-carat-r"></asp:LinkButton>
</ItemTemplate>
</asp:Repeater> 我不知道是什么问题!如果你发现任何线索请告诉我。
发布于 2015-05-11 12:59:03
当我们在使用数据源(如列表视图或中继器)的任何元素之外的元素属性(如<% %> )中使用像<asp:Button runat="server" text='<%# ...Codes... %>'></asp:Button>这样的代码块时,我们应该使用元素id,并让它在倒带后面的代码中使用--我们应该这样做:
<asp:HyperLink runat="server" NavigationUrl="#"><%= ...Codes... %></asp:HyperLink> 请注意,代码块的开头已从#更改为=!
https://stackoverflow.com/questions/29815995
复制相似问题