0
發現控制我的GridView其對數據綁定我需要HID Image控件,所以我做了這個代碼,但錯誤apear(rowIndex位置的網格視圖dosenot containe認定中),當我試圖找到控制錯誤在GridView控件
C#代碼:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Img = GridView1.Rows[e.RowIndex].FindControl("Logo") as Image ;
using (SqlConnection con = Connection.GetConnection())
{
string Sql = "Select Logo From Model where [email protected]";
SqlCommand com = new SqlCommand(Sql, con);
com.Parameters.Add(Parameter.NewInt("@Id", DDLModel.SelectedValue));
com.CommandType = CommandType.Text;
SqlDataReader dr = com.ExecuteReader();
if (dr.Read())
{
string Img2 = dr["Logo"].ToString();
if (Img2 == System.DBNull.Value.ToString())
{
Img.Visible = false;
}
}
}
}