2011-10-28 56 views
0

我烏代Satardekar,列表視圖下拉列表綁定不SqlDataSource的

在我nridubai.com的網站,我編輯列表視圖中使用EditTemplate事件信息。

而且我希望國家可以從選定的國家進行編輯。 而我沒有使用sqlDataSource。

我從頁面後面的代碼填充國家列表。爲此,我使用了OnItemDataBound事件。並在編輯模式下顯示所有國家的下拉列表。

高興這對我很好。

當我在editmode文本框中打開事件名稱的lisview時,顯示數據庫中的eventname。

像這樣,當第一次爲國家下拉列表加載編輯模式時,它必須顯示國家屬於事件。像TextBox控件。

我嘗試這樣

<asp:DropDownList ID="lstEditCountry" runat="server" 

         selectedValue='<%# Eval("country_name") %>' 
           Width="174" /> 

但thows例外。

請幫幫我。與例如..................

在此先感謝.....

回答

4

你必須綁定lstEditCountry到數據源當行處於編輯模式。見here

protected void List_ItemDataBound(object sender, ListViewItemEventArgs e) 
{ 

    //Verify there is an item being edited. 
    if (List.EditIndex >= 0) 
    { 

    //Get the item object. 
    ListViewDataItem dataItem = (ListViewDataItem)e.Item; 

    // Check for an item in edit mode. 
    if (dataItem.DisplayIndex == List.EditIndex) 
    { 

     // Preselect the DropDownList control with the Title value 
     // for the current item. 

     // Retrieve the underlying data item. In this example 
     // the underlying data item is a DataRowView object.   
     DataRowView rowView = (DataRowView)dataItem.DataItem; 

     // Retrieve the Title value for the current item. 
     String title = rowView["Title"].ToString(); 

     // Retrieve the DropDownList control from the current row. 
     DropDownList list = (DropDownList)dataItem.FindControl("lstEditCountry"); 

     //********populate the ddl here*********** 

     // Find the ListItem object in the DropDownList control with the 
     // title value and select the item. 
     ListItem item = list.Items.FindByText(title); 
     list.SelectedIndex = list.Items.IndexOf(item); 

    } 
    } 
} 
+0

謝謝...關於 \t 你要「lstEditCountry」綁定到數據源時,該行處於編輯模式。對於這個事件是必要的?手段在哪個事件我必須綁定listEditCountry dropdownlist。 –

+0

我更新了代碼。你已經有一個ItemDataBound事件,所以你可以在那裏添加它。 – rkw

+0

謝謝...以上幫助。從最近2天我對這個問題感到困惑.. Thanksssssssssssssssssssssssssssssssssssssssss –