开发者

error in finding control in gridview

开发者 https://www.devze.com 2023-01-12 16:21 出处:网络
I had gridview which on databound I need to hid Image co开发者_StackOverflow中文版ntrol so I did this code but error apear( grid view dosenot containe defination of RowIndex)when i tried to find contr

I had gridview which on databound I need to hid Image co开发者_StackOverflow中文版ntrol so I did this code but error apear( grid view dosenot containe defination of RowIndex) when i tried to find control

C# Code:

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;
                }
            }
        }
    }


GridViewRowEventArgs contains the row so you could try:

image = e.Row.FindControl("Logo") as Image;
0

精彩评论

暂无评论...
验证码 换一张
取 消