我在购物车视图页面上有产品面板,用户可以点击每个产品上的编辑链接按钮来编辑产品详细信息,但业务规则要求购物车一旦绑定,这意味着提交的状态字段该提交的表格从“新”更新为“绑定”,用户无法再编辑其产品。我一直在尝试一些不同的方法来禁用链接按钮(switchcase,如果那时等),但无济于事。有没有一种简单的方法可以将条件传递给linkbutton代码,使其可见性/启用属性以该表字段为条件?代码如下:
当我运行此块时,链接按钮仍然可见(如果我将其设置为.visible = false)和/或启用。 ??
string product = "SELECT ProductId FROM SubmissionProducts WHERE SubmissionId =" + x;
using (SqlConnection editConn = new SqlConnection(connectionString))
{
editConn.Open();
using (SqlCommand comntCmd = new SqlCommand(comnt, editConn))
{
SqlDataReader dr = comntCmd.ExecuteReader();
dr.Read();
var c = dr.GetInt32(0);
if (c > 0)
{
PanelQuote.Visible = false;
using (SqlCommand prodcmd = new SqlCommand(product, editConn))
{
SqlDataReader drpan = prodcmd.ExecuteReader();
while (dr.Read())
switch (drpan.GetInt32(0))
{
case 1:
LnbEpl.Enabled = false;
break;
case 2:
LnbFid.Enabled = false;
break;
case 3:
LnbCrim.Enabled = false;
break;
case 4:
LnbPub.Enabled = false;
break;
case 5:
LnbPriv.Enabled = false;
break;
case 6:
LnbNot.Enabled = false;
break;
case 7:
LnbEo.Enabled = false;
break;
default:
break;
}
}
}
else
PanelComment.Visible = false;
}
答案 0 :(得分:0)
这样做,我改变了几件事,删除whiles
并创建新连接,因为您提供的代码将抛出此异常"There is already an open DataReader associated with this Command which must be closed first."
SqlConnection editConn1 = new SqlConnection(connectionString);
SqlConnection editConn2 = new SqlConnection(connectionString);
editConn1.Open();
editConn2.Open();
SqlCommand comntCmd = new SqlCommand(comnt, editConn1);
SqlDataReader dr = comntCmd.ExecuteReader();
dr.Read();
var c = dr.GetInt32(0);
if (c > 0)
{
PanelQuote.Visible = false;
SqlCommand prodcmd = new SqlCommand(product, editConn2);
SqlDataReader drpan = prodcmd.ExecuteReader();
drpan.Read();
var d = drpan.GetInt32(0);
switch (d)
{
case 1:
LnbEpl.Enabled = false;
break;
case 2:
LnbFid.Enabled = false;
break;
case 3:
LnbCrim.Enabled = false;
break;
case 4:
LnbPub.Enabled = false;
break;
case 5:
LnbPriv.Enabled = false;
break;
case 6:
LnbNot.Enabled = false;
break;
case 7:
LnbEo.Enabled = false;
break;
default:
break;
}
}
else
{
PanelComment.Visible = false;
}