求gridview绑定问题,急急,解决就给分
我有两个表
表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();