0
有在下拉多個值..下拉值根據權利
e.g.
Car
Truck
Bike
Drink
Factory
還有一個登錄頁面爲Login.aspx。 登錄代碼
protected void Button1_Click(object sender, EventArgs e)
{
try
{
//Label1.BackColor = "F8D8D7";
loginmethod(txt_us.Text, txt_pwd.Text);
Response.Redirect("WebForm1.aspx");
}
catch(Exception)
{
Label1.Text = ("Incorrect UserName/Password");
Label1.Visible = true;
}
txt_us.Text = "";
txt_pwd.Text = "";
}
public bool loginmethod(string UserName,string Password)
{
TrackDataEntities1 td = new TrackDataEntities1();
splogin1_Result sp = td.splogin1(UserName, Password).FirstOrDefault();
if(sp.Password==txt_pwd.Text)
{
return true;
}
else
{
return false;
}
}
現在有兩個用戶..管理員和用戶。現在,我想要管理員登錄時,然後用他們的ID和密碼,然後他看到這個列表中的一些值,當用戶登錄時,他會看到這個列表中的一些值,例如當管理員登錄時,他可能只能看到工廠值和用戶登錄那麼他能夠看到,除了工廠的所有值
UPDATE
在login.aspx的我保存的用戶名是會議
Session["UserName"] = txt_us.Text;
在form.aspx
這裏我先創建SP
ALTER procedure [dbo].[spadminlist]
as
select Region from tblReg
where Region in ('Factory')
然後我在form.aspx
添加此SP //這個LINQ查詢選擇所有值
var list = tea.tblReg.AsEnumerable()
.Where(x => !x.Region.Any(char.IsDigit) && (x.Region != ""))
.GroupBy(x => x.Region)
.Select(x => new { Region = x.Key, Value = x.Key })
.ToList();
//這是管理員
if (Session["UserName"] = "admin")
{
List<spadminlist_Result> admin = tea.spadminlist().ToList();
}
and filling dropdown
if (!Page.IsPostBack)
{
regiondrop.DataSource = list;
regiondrop.DataTextField = "Region";
regiondrop.DataValueField = "Region";
regiondrop.DataBind();
Label4.Visible = false;
}
但本次車展的錯誤,也是我如何填寫與管理SP的下拉因爲查詢
Error 3 Cannot implicitly convert type 'object' to 'bool'. An explicit conversion exists (are you missing a cast?)
我該怎麼辦呢?
但下拉列表是另一種形式的登錄是另一種形式..還有在下拉幾個值,我使用LINQ查詢從數據庫中獲取.. – user6628729
是當在登錄時或登錄後顯示下拉菜單?如果在form.aspx代碼隱藏中登錄後,您需要編寫linq查詢來獲取用戶性質(即admin或normal),然後您可以處理下拉列表。 –
我在登錄後顯示下拉菜單 – user6628729