我有一个GridView
,我写了一个 DataBound 函数来分配一个工具提示。但它没有被分配。我写的函数是:
SqlCommand comd = new SqlCommand("SELECT Location_Profile_Name, " + Label10.Text + " as Home_Profile FROM Home_Profile_Master", con);
SqlDataAdapter da = new SqlDataAdapter(comd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView3.DataSource = dt;
GridView3.DataBind();
protected void GridView3_DataBound(object sender, EventArgs e)
{
var gv = (GridView)sender;
foreach (GridViewRow row in GridView3.Rows)
{
string label2 = row.Cells[2].Text.Trim();
if (label2.Length != 0)
{
con.Open();
string str = "SELECT Location_Profile_Tool_Tip FROM Location_Profile_List_ToolTip WHERE Location_Profile_Name='" + label2 + "'";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
row.Cells[2].ToolTip = dr[0].ToString().Trim();
}
con.Close();
}
}
}
当我调试label2为空。正在为另一个 Grid 执行相同的代码。怎么了...!!请帮助..!