Don't write all logic in this manner ever
1) Create saparate function for the logic
2) Manage page postback event
3) Call function from page postback event condition
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData();
}
}
public void BindData(){
SqlConnection con = new SqlConnection(strConnString);
con.Open();
SqlCommand command = new SqlCommand("BenReport", con) { CommandType = System.Data.CommandType.StoredProcedure };
SqlDataAdapter sda = new SqlDataAdapter();
command.Connection = con;
sda.SelectCommand = command;
DataSet ds = new DataSet();
sda = new SqlDataAdapter("BenReport", con);
sda.Fill(ds);
GRDBencount.DataSource = ds.Tables[0];
GRDBencount.DataBind();
con.Close();
}
for further information
Page.IsPostBack Property (System.Web.UI) | Microsoft Docs[
^]