2 回答
TA贡献1844条经验 获得超8个赞
目前还不清楚你想要完成什么,但我建议你多考虑这个问题,然后再考虑“翻译”。
这是否更接近您真正想要实现的目标?
//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 代码转换如下:
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贡献1798条经验 获得超3个赞
完成......在代码中缺少For循环......这样它就会读取每一行并将每一行值放入不同的SESSION......也在此行之前 DataRow dRow; 您必须将每个 SESSION = False 声明为默认值....
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 关注
- 330 浏览
添加回答
举报