我需要您的帮助以下代码。下面的代码假设用户在Orders表中没有任何记录向他显示UsOrderpanel和UsOrderlbl消息,如果他已经有,那么它将向他显示Usorderspan但实际上代码无论如何用户在订单表中是否有订单向他显示Usorderspan,该面板应仅在用户有记录时显示
protected void MyordersLinkBtn_Click(object sender, EventArgs e)
{
if (Session["UsrNme"] != null)
{
using (SqlConnection UsOrderCon = new SqlConnection(sc))
{
UsOrderCon.Open();
string chksUsOrderstring = "Select count (*) from Orders where UID=@chkUID";
SqlCommand ChkUsOrderCMD = new SqlCommand(chksUsOrderstring, UsOrderCon);
ChkUsOrderCMD.Parameters.AddWithValue("@chkUID", Payexictlbl.Text);
//Check if orderId exists in db and if not then show the message
if (!(Convert.ToInt32(ChkUsOrderCMD.ExecuteScalar()) > 0))
{
Usorderspan.Visible = true;
UsOrderpanel.Visible = false;
SqlDataAdapter UsOrderADPA = new SqlDataAdapter("SELECT [OrderNo], [UID], [SubDate], [EndSubDate], [Amount], [Product], [payntmeth] FROM [Orders] WHERE [UID] = @uSer ", sc);
var Userss = Session["UsrNme"];
UsOrderADPA.SelectCommand.Parameters.AddWithValue("@uSer", Userss);
DataSet UsOrderDST = new DataSet();
UsOrderADPA.Fill(UsOrderDST);
UsrOrdersCompLstViw.DataSource = UsOrderDST.Tables[0];
UsrOrdersCompLstViw.DataBind();
}
else
{
UsOrderpanel.Visible = true;
UsOrderlbl.Text = "You dont have any orders";
}
}
}
MultiView1.ActiveViewIndex = 8;
}
}
答案 0 :(得分:0)
更好地阅读你的问题,我认为你的情况反过来了。你说如果他没有Orders中的记录,你想向他展示UsOrderpanel和UsOrderlbl。如果他有,请告诉他Usorderspan。
查看您的代码,您可以这样做:如果他没有Orders中的记录,那么
Usorderspan.Visible = true;
UsOrderpanel.Visible = false;
...
如果他有记录你
UsOrderpanel.Visible = true;
UsOrderlbl.Text = "You dont have any orders";
您应该将条件改为
if (Convert.ToInt32(ChkUsOrderCMD.ExecuteScalar()) > 0)