Label1
的文本不变,这可能是此问题的原因吗?
try
{
string connectionString = @"Data Source = (localdb)\MSSQLLocalDB; Initial Catalog = db1; Integrated Security = True";
SqlConnection cnn = new SqlConnection(connectionString);
string query = "SELECT RNO FROM TABLE1 WHERE RNO='" + PRrno.Text + "'";
SqlCommand cd = new SqlCommand(query, cnn);
cnn.Open();
SqlDataReader reader = cd.ExecuteReader();
while (reader.Read())
{
Label1.Text = reader["RNO"].ToString();
}
reader.Close();
cnn.Close();
}
答案 0 :(得分:0)
Gaurav Thapa,就像我在评论中说的那样,请确保在aspx文件中,您的元素具有runat =“ server”并将所有想要刷新的元素都放在Ajax更新面板中
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>UpdatePanel</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel runat="server" id="UpdatePanel" updatemode="Always">
<ContentTemplate>
<asp:Label runat="server" id="PRrno" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
答案 1 :(得分:-2)
您必须在数据表中获取查询输出,然后从那里将DataTable值转换为字符串。 检查您是否有权访问标签。
Label.Text = //从DataTable转换而来的字符串