I had stored procedure which get data where Id=@id and the @id which pass to stored from gridview I tried to do that but I couldnot please any one help me
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
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", GridView1.SelectedDataKey));
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;
}
}
}
}
Not sure what exactly you want to do here. GridView1_RowDataBound will be invoked for every row present in the gridview – do you want to run the query for each row in gridview to retrieve the data? If yes then you can use
e.Row.DataItemproperty to get underlying data (DataRowView if using data-table/view or object instance if using object data source). You can also usee.Row.DataItemIndexto look up into your data source to get the corresponding data row and get the id from there.