2015-01-07 129 views
0

我想知道如何更改ListView的視圖或模板(不是%100確定它是什麼稱呼)。我目前使用的過程是繞過listview的內置函數來插入,更新和刪除。這是我更新的例子:更改ListView模板/查看

protected void LV_Products_ItemUpdating(object sender, ListViewUpdateEventArgs e) 
{ 
    int fail = DatabaseInteraction.UpdateJobProducts(Int32.Parse(JobProductKeyLabel.Text), Int32.Parse(JobIDLabel.Text), ProductDate, ProductsDDL.SelectedItem.ToString(), ProductQuantity, ProductRate); 

    //Check to see if the insert was successful. No message if yes, but alert user if no. 
    if (fail == -1) 
    { 
     AlertMessage("Update failed."); 
    } 

    //We need to cancel the "actual" insert now so it doesn't fail. 
    e.Cancel = true; 
} 

,我使用e.Cancel = true;是因爲它會取消實際的更新,讓我的自定義更新發生的原因。

,我經過更新的過程如下:

ListView中 - 點擊編輯按鈕

-ListView改爲 「編輯視圖」

- 製作更改,以記錄

- 點擊更新(這是事件處理程序)

因此,一旦我完成了我的更新(這工作完全正常。)我的列表視圖保持在U更新「視圖」。那麼我怎樣才能從後面的代碼中改變我的列表視圖?

回答

0

爲了從編輯視圖改回我實際上已將列表視圖中的更新按鈕更改爲取消按鈕。因此,在取消按鈕的句柄進行插入工作。取消按鈕會自動將列表視圖更改回原始格式。