怎样为datalist中的控件绑定数据
protectedvoidDataList1_ItemCommand(objectsource,DataListCommandEventArgse){if(e.Comma...
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
{
if (e.CommandName == "hf")
{
lblhtyhm.Visible = true;
this.lblhtyhm.Text = Session["UserName"].ToString();
string ContId = Request["ContId"];
SqlConnection con = DB.createDB();
con.Open();
SqlCommand cmd = new SqlCommand("select a.*,b.* from tb_Users as a join tb_Content as b on a.UserName=b.UserName where b.ContId='" + ContId + "'", con);
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
this.txthtbt.Text = sdr["Subject"].ToString();
this.txthtbh.Text = sdr["ContId"].ToString();
}
}
这是一段书上的代码,可是我自己写时用this却取不到txthtbh.text。想问一下这是怎么回事?(控件是放在datalist中的Item Template中的。 展开
{
if (e.CommandName == "hf")
{
lblhtyhm.Visible = true;
this.lblhtyhm.Text = Session["UserName"].ToString();
string ContId = Request["ContId"];
SqlConnection con = DB.createDB();
con.Open();
SqlCommand cmd = new SqlCommand("select a.*,b.* from tb_Users as a join tb_Content as b on a.UserName=b.UserName where b.ContId='" + ContId + "'", con);
SqlDataReader sdr = cmd.ExecuteReader();
sdr.Read();
this.txthtbt.Text = sdr["Subject"].ToString();
this.txthtbh.Text = sdr["ContId"].ToString();
}
}
这是一段书上的代码,可是我自己写时用this却取不到txthtbh.text。想问一下这是怎么回事?(控件是放在datalist中的Item Template中的。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询