在Asp.net的所有页面上的Lable中加载DropDown选定文本 [英] Load DropDown Selected Text in Lable on all pages in Asp.net
本文介绍了在Asp.net的所有页面上的Lable中加载DropDown选定文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我在登录页面上有DropDownList。现在我想在所有页面上显示所有页面上的下拉选定文本,就像我们在所有页面上显示登录用户名一样。我怎么能这样做
请帮助...........
解决方案
点击存储会话中的下拉列表选定文本
受保护 < span class =code-keyword> void btn_Click( object sender,EventArgs e)
{
// 代码
会话[ abc] = dropdownName.Selected.Text;
}
检查会话变量并在标签中指定会话存储值
受保护 void Page_Load( object sender,EventArgs e)
{
// 代码
if (会话[ abc]!= null )
{
/ / 代码
lblShow.Text =会话[ ABC跨度>]的ToString();
}
}
使用最适合此类情况的母版
受保护的void btn_click (对象发送者,EventArgs e)
{
Session [UserID] = dropdownlistname.SelectedItem.Text;
}
您可以在登录页面中使用此代码。
< span class =code-keyword> protected void DropDownList1_SelectedIndexChanged( object sender,EventArgs e )
{
会话[ MyLabel] = DropDownList1.SelectedItem.Text ;
}
您可以在任何页面中使用此值,例如:
Label1.Text =会话[ MyLabel< /跨度>]的ToString();
Hello,
I have DropDownList on Login Page. Now i want to show dropdown selected text on all pages in lable like we show Login Username on all pages . How can i do this
please Help...........
解决方案
on click store your dropdownlist selected text in session
protected void btn_Click(object sender, EventArgs e) { // code Session["abc"] = dropdownName.Selected.Text; }
check session variable and assign session stored value in label
protected void Page_Load(object sender, EventArgs e) { // code if (Session["abc"] != null) { // code lblShow.Text = Session["abc"].ToString(); } }
Use Master Page that best suitable for this kind of situation
Protected void btn_click(object sender, EventArgs e)
{
Session["UserID"] = dropdownlistname.SelectedItem.Text;
}
You can use this code in your login page.
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { Session["MyLabel"] = DropDownList1.SelectedItem.Text; }
and you can use this value in your any page, like this.
Label1.Text = Session["MyLabel"].ToString();
这篇关于在Asp.net的所有页面上的Lable中加载DropDown选定文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文