我有网格视图,在数据绑定我需要隐藏图像控件所以我做了这个代码但是错误apear(网格视图dosenot容纳RowIndex的定义)当我试图找到控件时
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 Id=@Id";
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;
}
}
}
}