名称';文本框1';在当前上下文中不存在
本文关键字:上下文 不存在 文本 名称 | 更新日期: 2023-09-27 18:27:46
我收到此错误当我尝试执行此时,名称"Textbox1"在当前上下文中不存在
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
string connect = ConfigurationManager.ConnectionStrings["TDBSConnectionString"].ConnectionString;
string query = "SELECT news, news_date FROM [IBSI].[dbo].[ibsi.news]";
if (query != null)
{
using (SqlConnection conn = new SqlConnection(connect))
{
using (SqlCommand cmd = new SqlCommand(query, conn))
{
conn.Open();
SqlDataReader rdr = cmd.ExecuteReader();
if (rdr.HasRows)
{
while (rdr.Read())
{
Textbox1.Text=rdr["news"].ToString() ;
}
}
}
}
}
else
{
Response.Write("<p>No customer selected</p>");
}
Response.End();
}
</script>
文本框1为现有
<asp:TextBox ID="TextBox1" runat="server" Height="168px" TextMode="MultiLine"
Width="303px"></asp:TextBox>
我的代码可能出了什么问题??
TextBox1与TextBox1不同。尝试使用B而不是B,因此您的代码应该是:
...
while (rdr.Read())
{
TextBox1.Text=rdr["news"].ToString() ;
}
...