簡體   English   中英

ASP.NET ListView無法正確顯示數據

[英]Asp.net listview does not display data correctly

我的問題是,當我第一次在列表視圖中顯示數據時,它將正確顯示,但是當我第二次顯示數據時,列表視圖將無法正確更新數據。 我做了一個用於與listview進行數據綁定的函數,我已經在pageLoad和其他方法中調用了它。 有人可以給我解決辦法嗎?

我還上傳了源代碼以獲取更多詳細信息。

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

protected void LoadDataIntoListView()
{
    Users objQuery = new Users();
    string adminID = "Here is my query to get the data from MS-SQL";
    objQuery.ExecuteSql(str);
    if (objQuery.RowCount > 0)
    {
        Title = "Row affected";
        lstAppointments.Items.Clear();
        lstAppointments.DataSource = objQuery.DefaultView;
        lstAppointments.DataBind();
    }
    else
    {
        Title = "None Row affected";
    }
}

protected void btnDelete_Click(object sender, EventArgs e)
{
    string caseID = (string)Session["caseID"];
    //string updateQuery = "update Cases set sCaseStatus='cancel' where iCaseID= '" + caseID + "'";
    Cases objCases = new Cases();
    objCases.LoadByPrimaryKey(Convert.ToInt32(caseID));
    if (String.Equals(objCases.SCaseStatus, "cancel"))
    {
        Page.Title = "No Update";
        ModalPopupExtender1.Hide();
    }
    else
    {
        objCases.SCaseStatus = "cancel";
        objCases.Save();
        Page.Title = "No Update";

        ModalPopupExtender1.Hide();
        lstAppointments.Items.Clear();
        LoadDataIntoListView();
    }
}

提前致謝。

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

您綁定的數據不是回發。 這意味着當您回發到同一頁面時,它不會綁定數據。 如果要在每次頁面加載時將其綁定,請在Page_Load調用函數LoadDataIntoListView()

暫無
暫無

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

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