2013-04-29 95 views
0

我的問題是,當我第一次在列表視圖中顯示數據,然後它顯示正確,但是當我第二次顯示數據時,然後listview不正確地更新數據。我已經做了一個listview的數據綁定功能,我已經在pageLoad和其他一些方法中調用。 任何人都可以請給我一個解決方案嗎?Asp.net listview不能正確顯示數據

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

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(); 
    } 
} 

在此先感謝。

+1

請提供有關您的問題的更多信息:_「當我第二次顯示數據,然後listview不會正確更新數據」_。什麼意思_第二次_什麼意思_不正確_? – 2013-04-29 07:36:29

+0

夫婦的事情,你只是databinding沒有回發事件(雖然我想這是有意的),其次,如果'objQuery.RowCount> 0'失敗,你不會做一個數據綁定,所以''無行受影響的「永遠不會被設置。 – DGibbs 2013-04-29 07:41:30

回答

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

您在綁定數據時不是回發。這意味着它在回發到同一頁面時不會綁定數據。如果你想綁定每頁加載,請撥打Page_Load的函數LoadDataIntoListView()