2 回答

TA貢獻(xiàn)1844條經(jīng)驗(yàn) 獲得超8個贊
目前還不清楚你想要完成什么,但我建議你多考慮這個問題,然后再考慮“翻譯”。
這是否更接近您真正想要實(shí)現(xiàn)的目標(biāo)?
//First I'll create an array of every value to be inspected and iterate through it....
foreach (var c in new[] {"104", "105", "106"})
{
//Then I'll check the current value (considering the value of dRow["Active"]...
Session[c] = ( ((bool)dRow["Active"]) && (dRow["Code"].ToString() == c) ) //Thanks to @jjwillmc observation
}
如果您更喜歡僅使用 IF,則 VB 代碼轉(zhuǎn)換如下:
If roleRow.Item("Code").ToString() = "101" Then 'Admin Settings
If roleRow.Item("Active") = True Then Session("101") = True Else Session("101") = False
End If
If roleRow.Item("Code").ToString() = "102" Then 'Summaries / Reports
If roleRow.Item("Active") = True Then Session("102") = True Else Session("102") = False
End If
If roleRow.Item("Code").ToString() = "103" Then 'Invoices List
If roleRow.Item("Active") = True Then Session("103") = True Else Session("103") = False
End If
變成:
if (roleRow.Item("Code").ToString() == "101") //Admin Settings
{
if (roleRow.Item("Active"))
Session["101"] = true;
else
Session["101"] = False;
//Or simply: Session["101"] = (roleRow.Item("Active"));
}
if (roleRow.Item("Code").ToString() == "102") //Summaries / Reports
{
if (roleRow.Item("Active"))
Session["102"] = true;
else
Session["102"] = false;
//Or simply: Session["102"] = (roleRow.Item("Active"));
}
if (roleRow.Item("Code").ToString() == "103") //Invoices List
{
if (roleRow.Item("Active"))
Session["103"] = true;
else
Session["103"] = false;
//Or simply: Session["103"] = (roleRow.Item("Active"));
}
希望能幫助到你。

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個贊
完成......在代碼中缺少For循環(huán)......這樣它就會讀取每一行并將每一行值放入不同的SESSION......也在此行之前 DataRow dRow; 您必須將每個 SESSION = False 聲明為默認(rèn)值....
DataRow dRow;
if (aDT.Rows.Count > 0)
{
for (var i = 0; i <= aDT.Rows.Count -1; i++)
{
dRow = aDT.Rows[i];
if (dRow["Code"].ToString() == "101" && (Boolean)dRow["Active"] == true)
{
Session["101"] = true;
}
else if (dRow["Code"].ToString() == "102" && (Boolean)dRow["Active"] == true)
{
Session["102"] = true;
}
else if (dRow["Code"].ToString() == "103" && (Boolean)dRow["Active"] == true)
{
Session["103"] = true;
}
- 2 回答
- 0 關(guān)注
- 358 瀏覽
添加回答
舉報(bào)