|
I have two tables
Table A
audioID audioName UserId audioRemark
Table B
ID CommTxt(message) audioID
I want to use gridview to display all audio information of a user through UserId
Display like this
audioName audioRemark countcomm (count the number of stays)
How to do this, do you use gridview nesting
Take a look, what I did below, there is a problem with this, thank you for your advice! ! !
public int commcount; bind this statistical field in 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 table 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();
}
} |
|