gridview第一列做了链接,一点进入新页面,然后把这一行的数据显示在新页面的textbox中,
这是做的跳转<asp:HyperLinkID="HyperLink1"runat="server"DataNavigateUrlFields="news_id"Navig...
这是做的跳转 <asp:HyperLink ID="HyperLink1" runat="server" DataNavigateUrlFields="news_id"
NavigateUrl='<%# Eval("news_id", "查看通知.aspx?id={0}") %>'
Text='<%# Eval("news_id") %>'></asp:HyperLink>
这是跳转之后的protected void Page_Load(object sender, EventArgs e)
{
this.TextBox1.Text = getcontent();
}
public string getcontent()
{
string content = null;
int id = Convert.ToInt32(Request.QueryString["news_id"]);
string sqlstr = "select news_content from news where news_id=" + id;
string strconn1 = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\毕业设计管理系统1\App_Data\database.mdf;Integrated Security=True;User Instance=True";
SqlConnection con = new SqlConnection(strconn1);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = sqlstr;
content = Convert.ToString(cmd.ExecuteScalar());
con.Close();
return content;
}
能帮我看下哪有问题么?这样做textbox里什么都没 展开
NavigateUrl='<%# Eval("news_id", "查看通知.aspx?id={0}") %>'
Text='<%# Eval("news_id") %>'></asp:HyperLink>
这是跳转之后的protected void Page_Load(object sender, EventArgs e)
{
this.TextBox1.Text = getcontent();
}
public string getcontent()
{
string content = null;
int id = Convert.ToInt32(Request.QueryString["news_id"]);
string sqlstr = "select news_content from news where news_id=" + id;
string strconn1 = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\毕业设计管理系统1\App_Data\database.mdf;Integrated Security=True;User Instance=True";
SqlConnection con = new SqlConnection(strconn1);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = sqlstr;
content = Convert.ToString(cmd.ExecuteScalar());
con.Close();
return content;
}
能帮我看下哪有问题么?这样做textbox里什么都没 展开
2个回答
展开全部
把这个直接写在Page_Load里试一试
//判断URL参数个数
if (this.Request.QueryString.Count > 0)
{
int id = Convert.ToInt32(Request.QueryString["news_id"]);
string sqlstr = "select news_content from news where news_id=" + id;
string strconn1 = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\毕业设计管理系统1\App_Data\database.mdf;Integrated Security=True;User Instance=True";
SqlConnection con = new SqlConnection(strconn1);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = sqlstr;
//实例化数据适配器对象
SqlDataAdapter adpt = new SqlDataAdapter();
//设定查询命令对象
adpt.SelectCommand = com;
//实例化DataSet
DataSet ds = new DataSet();
//填充DataSet
adpt.Fill(ds);
//判断数据集中是否存在数据
if (ds.Tables[0].Rows.Count > 0)
{
//将表中的数据显示在界面上
this.TextBox1.Text = ds.Tables[0].Rows[0]["NewsName"].ToString();
return;
}
}
//判断URL参数个数
if (this.Request.QueryString.Count > 0)
{
int id = Convert.ToInt32(Request.QueryString["news_id"]);
string sqlstr = "select news_content from news where news_id=" + id;
string strconn1 = @"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\毕业设计管理系统1\App_Data\database.mdf;Integrated Security=True;User Instance=True";
SqlConnection con = new SqlConnection(strconn1);
con.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = sqlstr;
//实例化数据适配器对象
SqlDataAdapter adpt = new SqlDataAdapter();
//设定查询命令对象
adpt.SelectCommand = com;
//实例化DataSet
DataSet ds = new DataSet();
//填充DataSet
adpt.Fill(ds);
//判断数据集中是否存在数据
if (ds.Tables[0].Rows.Count > 0)
{
//将表中的数据显示在界面上
this.TextBox1.Text = ds.Tables[0].Rows[0]["NewsName"].ToString();
return;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询