|
我有两个表
表A
audioID audioName UserId audioRemark
表B
ID CommTxt(留言) audioID
我想用gridview 通过UserId显示某个用户所有的audio信息
这样显示
audioName audioRemark countcomm(统计留的次数)
这个怎么做,用不用gridview 嵌套
看看,我下面做的,,这个有问题,,谢谢指点!!!
public int commcount; 在html里绑定这个统计字段,
private void MyCreateBind()
{
int uid = Int32.Parse(Session["UserId"].ToString());
string str = "select * from UsersAudioView where UserId=" + uid;
SqlConnection myCon = new SqlConnection(ConfigurationManager.ConnectionStrings["mysql"].ConnectionString);
myCon.Open();
SqlDataAdapter sda = new SqlDataAdapter(str, myCon);
DataSet ds = new DataSet();
sda.Fill(ds, "UsersAudioView ");
AudioInfoGV.DataSource = ds.Tables["UsersAudioView "];
AudioInfoGV.DataBind();
myCon.Close();
}
protected void audioInfoGV_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// DataList dali = (DataList)e.Row.FindControl("DataList1");
Label lblvid = (Label)e.Row.FindControl("lblaudioId");
string aid= lblvid.Text.ToString();
string str = "select count(*)as aa from 表B where audioId='" + aid+ "'";
SqlConnection myCon = new SqlConnection(ConfigurationManager.ConnectionStrings["mysql"].ConnectionString);
myCon.Open();
SqlCommand myCmd = new SqlCommand(str, myCon);
// SqlDataAdapter sda = new SqlDataAdapter(str, myCon);
// DataSet ds = new DataSet();
// sda.Fill(ds);
SqlDataReader dr = myCmd.ExecuteReader();
if (dr.Read())
{
commcount = Int32.Parse(dr["aa"].ToString());
}
else
{
commcount = 0;
}
// dr.Close();
// dali.DataSource = ds;
// dali.DataBind();
dr.close();
}
} |
|