簡體   English   中英

在按鈕單擊中使用Page_Load方法

[英]Using Page_Load method in button click

我嘗試在單擊btnSubmit之后調用Page_Load方法。 對於我的Page_Load我在caseprogress != 'ongoing'框上進行了數據綁定,其中column caseprogress != 'ongoing' 然后為我的btnSubmit_Click插入一些數據到另一個表中,更新caseprogress = 'completed'並調用Page_Load方法。 但是我的下拉列表框似乎沒有重新綁定。 (除非刷新頁面)我嘗試在其他頁面上使用此方法,但此方法不起作用。 僅供參考,我在此頁面上沒有任何更新面板。 另一個正在工作的人也是如此。

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        //Bind data to Dropdownlist box
    }
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
    //Insert / Update data of sql data table

   Page_Load(null, EventArgs.Empty);
}

您可以使用方法綁定下拉列表

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        BindData();
    }
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
    //Insert / Update data of sql data table

   BindData();
}

private void BindData()
{
    String policeid = (String)Session["policeid"];
    SqlConnection con = new SqlConnection("Data Source = localhost; Initial Catalog = MajorProject; Integrated Security= SSPI");
    con.Open();
    DataSet ds = new DataSet();
    SqlDataAdapter da = new SqlDataAdapter("Select mr.memberreportid From PoliceAccount pa, MemberReport mr Where pa.policeid = '" + policeid + "' And pa.handle = mr.memberreportid And mr.caseprogress = 'ongoing'", con);
    da.Fill(ds);
    ddlMemberReportID.DataSource = ds;
    ddlMemberReportID.DataTextField = "memberreportid";
    ddlMemberReportID.DataValueField = "memberreportid";
    ddlMemberReportID.DataBind();
    con.Close();
}

並刪除Page_Load(null, EventArgs.Empty); 代碼行

您的問題可能是您對Page_Load(null, EventArgs.Empty);調用Page_Load(null, EventArgs.Empty); 這將導致對Page_Load的兩次調用,您在btn_Click事件內部調用的最后一個調用將具有IsPostback = true並且您的數據將不被綁定。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM