从数据库中获取数据,同时查询,再返回,如果有数据,显示“有”,如果没有,则显示“无”
两张表
Id是从绑定数据的时候的来的
//注意引索值的获取
protected void GVmasterList_RowDataBound(object sender, GridViewRowEventArgs e)
{
//如果是绑定数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//鼠标经过时,行背景色变
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
//鼠标移出时,行背景色变
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
}
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}
//注意
if(e.Row.RowType == DataControlRowType.DataRow)
{
//在gridview数据绑定时将第4列的文本数据转换成短日期格式
e.Row.Cells[3].Text = Convert.ToDateTime(e.Row.Cells[3].Text).ToShortDateString();
Label Label1seat = (Label)e.Row.FindControl("lblTAppendix");
int nid = int.Parse(GVTopicList.DataKeys[e.Row.RowIndex].Value.ToString());
DataSet dst = new DataSet();
SqlDataAdapter dap = ttopicmanager.PTopicListBytopicIdGet(nid);
dap.Fill(dst);
DataTable dt = dst.Tables[0];
if (dt.Rows.Count > 0)
{
Label1seat.Text = "有";
}
else
{
Label1seat.Text = "无";
}
}
}