Implementation of IsPostBack in page load

后端 未结 8 1042
你的背包
你的背包 2020-12-06 00:07

The more I use ASP.NET, the more if (!IsPostBack) {} seems pointless...

First example:

For example, I just Googled an issue, they said use this

8条回答
  •  醉酒成梦
    2020-12-06 01:00

    protected void Page_Load(object sender, EventArgs e)            
    {
        if (!IsPostBack) { 
            SqlConnection conn = new SqlConnection("Data Source=-----; Database=-----; Integrated Security=True");
            SqlDataAdapter da = new SqlDataAdapter();
            conn.Open();
            da.SelectCommand = new SqlCommand("Select Command",conn);
            conn.Close();
            DataTable dt = new DataTable();
            da.Fill(dt);
    
            ddlSearch.DataSource = dt;
            ddlSearch.DataTextField = "---";
            ddlSearch.DataValueField = "---";
            ddlSearch.DataBind();
        }
    }
    

提交回复
热议问题