I have a button click event which insert data to database.I need to call a function inside this click event to display the data from database after the button is clicked.
This is the button click event.
protected void cmt_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
DataListItem dli = (DataListItem)btn.NamingContainer;
TextBox tx = (TextBox)dli.FindControl("tb_cmt");
Label lb = (Label)dli.FindControl("lbl_sid");
string userid = Session["userid"].ToString();
sq.connection();
SqlCommand cmd = new SqlCommand("insert into comment(ecomment,sid,my_date,reg_id) values(@myecomment,@mysid,@mydate,@reg_id)", sq.con);
cmd.Parameters.AddWithValue("@myecomment", tx.Text);
cmd.Parameters.AddWithValue("@mysid", lb.Text);
cmd.Parameters.AddWithValue("@mydate", DateTime.Now.ToString("h:mm, MMM dd, yyyy"));
cmd.Parameters.AddWithValue("@reg_id", userid);
cmd.ExecuteNonQuery();
sq.con.Dispose();
sq.con.Close();
tx.Text = "";
show_comment();
}
And i want to call this function at the end of the click event.
protected void mydatalist_ItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item)
{
DataList dl = e.Item.FindControl("dl_cmt") as DataList;
string str = gstr;
sq.connection();
SqlCommand cmd = new SqlCommand("select top 4 * from comment where sid='" + str + "' order by my_date desc", sq.con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
dl.DataSource = ds;
dl.DataBind();
}
}