I'm currently using ASP.net and C#. I want to add an "Edit" button to my grid view, but I don't know how can I add a command on the button. And I also would gladly welcome any suggestions on how I can enhance this gridview.
protected void Page_Load(object sender, EventArgs e)
{
if (Session["id"] == null)
{
Response.Redirect("~/LoginPage.aspx");
}
lbl_name.Text = "Welcome :: " + Session["username"];
using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["DBCon"].ConnectionString))
{
constructor var = new constructor();
con.Open();
string sql = "SELECT product_name,product_price,product_desc,product_stock FROM product_tbl";
MySqlCommand cmd = new MySqlCommand(sql, con);
MySqlDataReader reader1 = cmd.ExecuteReader();
reader1.Close();
try
{
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "user_tbl");
GridView1.DataSource = ds.Tables["user_tbl"];
GridView1.DataBind();
}
catch (Exception ex)
{
lbl_result.Text = "ERROR>>" + ex.Message + "!";
}
finally
{
con.Close();
sql = null;
}
}
}