两个Datalist怎么绑定啊??????
两个Datalist怎么绑定啊??????求解!!!!!!!!!!!!
下面是我一个Datalist和aspnetpage的绑定
帮我绑多一个,怎么绑
protected void Page_Load(object sender, EventArgs e)
{
this.Page.Title = " 健康档案信息-个人档案-基本信息" + mssql.web_name.ToString();
if (!IsPostBack)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConSql"]);
con.Open();
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandText = "select count(*) from PersonalInfor where InfoName='"+Session["user"].ToString()+"'";
AspNetPager1.PageSize = 5;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
int shujin = (int)com.ExecuteScalar();
con.Close();
DataListDataBind();
}
}
private void DataListDataBind()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConSql"]);
SqlDataAdapter dr = new SqlDataAdapter("select * from PersonalInfor where InfoName='" + Session["user"].ToString() + "'", con);
DataSet ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "PersonalInfor");
DataList1.DataSource = ds.Tables["PersonalInfor"];
DataList1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
DataListDataBind();
}
}
上面的绑定有一项是OldId
下面我想绑多一个表 id, OldId,Temperature,.....
求如何绑定
--------------------编程问答-------------------- --------------------编程问答-------------------- sql和代码在一起啦??和我当初一样啊 --------------------编程问答-------------------- 那你是怎么解决的???????????我上面只是一个的绑定 --------------------编程问答-------------------- 我前两天才问的问题,你现在又来问呀,呵 ,简单,用SQL搞定 --------------------编程问答-------------------- 怎么做啊????????? --------------------编程问答-------------------- 可以发你的代码给我看看嘛??
if (!IsPostBack)--------------------编程问答-------------------- SQL里面写个视图 直接查视图
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConSql"]);
con.Open();
SqlCommand com = new SqlCommand();
com.Connection = con;
com.CommandText = "select Chronic.* FROM PersonalInfor,Chronic where Chronic.ChronicId = PersonalInfor.ChronicId and PersonalInfor.InfoName='" + Session["user"].ToString() + "'";
AspNetPager1.PageSize = 5;
AspNetPager1.RecordCount = (int)com.ExecuteScalar();
int shujin = (int)com.ExecuteScalar();
con.Close();
DataListDataBind();
DataList2Bind();
}
}
}
private void DataListDataBind()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConSql"]);
SqlDataAdapter dr = new SqlDataAdapter("select Chronic.* FROM PersonalInfor,Chronic where Chronic.ChronicId = PersonalInfor.ChronicId and PersonalInfor.InfoName='" + Session["user"].ToString() + "'", con);
DataSet ds = new DataSet();
dr.Fill(ds, AspNetPager1.PageSize * (AspNetPager1.CurrentPageIndex - 1), AspNetPager1.PageSize, "Chronic");
DataList1.DataSource = ds.Tables["Chronic"];
DataList1.DataKeyField = "Id";
DataList1.DataBind();
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
DataListDataBind();
}
void DataList2Bind()
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["ConSql"]);
SqlDataAdapter sr = new SqlDataAdapter("select * from PersonalInfor where InfoName='" + Session["user"].ToString() + "'", con);
DataSet dr=new DataSet ();
DataList2.DataSource = dr.Tables["PersonalInfor"];
sr.Fill(dr, "PersonalInfor");
DataList2.DataBind();
}
或者在第一个DATALIST有个每行绑定的时候触发的事件,在事件里取得行的KEY再查
补充:.NET技术 , ASP.NET