I have product panels on a cart-view page where the user can click an edit linkbutton on each product to edit the product details, but business rules require that once the cart has been bound, which means the status field of the submission table for that submission is updated from "new" to "bound", the user can no longer edit their products. I've been trying a few different methods to disable the linkbuttons (switchcase, if then, etc.), but to no avail. Is there a simple way I can pass a condition into the linkbutton code that makes their visibility/enable attributes conditional upon that table field? Code below:
When I run this block, the linkbuttons are still visible (if I set it to .visible=false) and or enabled. ??
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:
开发者_如何学Python break;
}
}
}
else
PanelComment.Visible = false;
}
This works, couple of things I changed, drop the whiles
and create new connection because that code you gave will throw this exception "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;
}
精彩评论