0

我在 c# 中使用 asp.net,我的 aspx 代码如下所示

<html xmlns="http://www.w3.org/1999/xhtml">
<body>

<asp:Panel ID="panel1" runat="server">
<table><tr><td><asp:Label ID="Label2" runat="server" Font-Bold="True" 
        Font-Underline="True"></asp:Label></td></tr>

 <tr> <td>
   <asp:Button ID="btnsubmit" runat="server" Text="Submit" BackColor="#993300" 
       ForeColor="White" onclick="btnsubmit_Click" /></td>
<td>
    <asp:Button ID="btnlogout" runat="server" Text="Logout" BackColor="#993300" 
       ForeColor="White" onclick="btnlogout_Click"  />
</td>
</tr>
</table>

现在这是我的 C# 代码

cmd.CommandText = "update TrackingFaculty_det SET Type=@Type WHERE (FID=@FID) and DATEDIFF(d,TrackingFaculty_det.LastUpdateDate,GETDATE())>60";

提交按钮中存在,只要上述查询为真并执行,我就需要显示提交按钮,否则我不需要显示提交按钮

 protected void btnsubmit_Click(object sender, EventArgs e)
{
    string type = "c";
    string FID = Session["FID"].ToString();
    SqlConnection cn = new SqlConnection();
    SqlCommand cmd = new SqlCommand();
    //int str_diff = Convert.ToInt32(ConfigurationManager.AppSettings["Difference"]);
    cn.ConnectionString = @"Data Source=BOPSERVER;Initial Catalog=Project;Integrated Security=True";
    cn.Open();
    cmd.CommandText = *"update TrackingFaculty_det SET Type=@Type WHERE (FID=@FID) and DATEDIFF(d,TrackingFaculty_det.LastUpdateDate,GETDATE())>60*";
    cmd.Connection = cn;
    cmd.Parameters.Add("@FID",SqlDbType.VarChar,10);
    cmd.Parameters["@FID"].Value = FID;
    cmd.Parameters.Add("@Type", SqlDbType.VarChar, 1);
    cmd.Parameters["@Type"].Value = type;
    cmd.ExecuteNonQuery();
    cn.Close();

    Response.Redirect("~/Faculty/Personaldet.aspx");
}
protected void btnlogout_Click(object sender, EventArgs e)
{
    Response.Redirect(@"~\home.aspx");
}

此图像应仅在update TrackingFaculty_det SET Type=@Type WHERE (FID=@FID) and DATEDIFF(d,TrackingFaculty_det.LastUpdateDate,GETDATE())>60"执行时显示

4

2 回答 2

0

将您的提交按钮过程放在表单加载事件上然后添加一个条件如果它是真的然后隐藏/禁用 btnsubmit

于 2013-10-07T06:58:54.127 回答
0

您在同一个按钮上触发查询这是不可行的,您需要select query像这样触发

Select * from TrackingFaculty_det  where  FID=@FID and 
DATEDIFF(d,TrackingFaculty_det.LastUpdateDate,GETDATE())>60

在页面加载之类的东西上,它返回真/假,获取结果,现在取决于结果集按钮属性

Button1.Enabled = false; // make button as disable
Button1.Visible = false; // make button invisible
于 2013-10-07T07:01:26.153 回答