我有一個GridView
,我寫了一個DataBound函數來分配工具提示。但它沒有被分配。我寫的功能是: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爲空。相同的代碼正在執行另一個網格。哪裏不對...!!請幫助..!
顯示,其中標籤放置一排 – sll
看看裏面你的代碼再次聲明瞭例如GV事情,但在代碼中,你使用它ASPX/ASCX的一部分?? – MethodMan
'label2'不能爲null,它的長度可以是0。 –