2011-01-18 25 views
1

編集が有効になっているListViewを作成しました。ウィザードはテキストボックスを使用してテーブルを生成しましたが、いくつかのオプションでドロップダウンリストを使用する必要があります。ListView DropDownList Edit ListView

私は

<asp:DropDownList ID="ActionStatusTextBox" runat="server"> 
        <asp:ListItem Value="Ongoing">Ongoing</asp:ListItem> 
        <asp:ListItem Value="Open">Open</asp:ListItem> 
        <asp:ListItem Value="Closed">Closed</asp:ListItem> 
</asp:DropDownList> 

ドロップダウンリストが正常に生成しますが、提出し、databse自体に入らないドロップダウンリストを作成しました。

<%# Bind("ActionStatus") %>' 

上記のスニペットは、データをバインドするために、どこかで使用する必要がありますが、どのパラメータには、データを渡すために装着する必要がありますか?

私はすべてを試して、それは私に右頭痛を与える!

おかげ

答えて

0

は、あなたがしようとしました:

<asp:DropDownList .. SelectedValue='<%# Bind("ActionStatus") %>' /> 

をSelectedValueのプロパティが表示されませんが、私はあなたがそれをこのように設定することができると信じて。

HTH。

0

データベースに何を挿入しようとしていますか?リスト項目を手動で追加する場合は、何もバインドする必要はありません。

string value = ActionStatusTextBox.SelectedValue; 
0

私は同じ問題がありました。このスレッドをチェックアウト:Why is employee_id not being inserted into database

キーは、機能を追加することにあった。基本的にはそれを必要なときにドロップダウンの値を設定し、私はこれをした後、値はに行っていた

Protected Sub AbsentListView_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.ListViewInsertEventArgs) Handles AbsentListView.ItemInserting 
    e.Values("employee_id") = DirectCast(AbsentListView.InsertItem.FindControl("ExcusedAbsences_employee_idDropDownList2"), DropDownList).SelectedValue 
End Sub 

データベース。

0
protected void ContactsListView_ItemDataBound(object sender, ListViewItemEventArgs e) 
{ 

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

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

    // Check for an item in edit mode. 
    if (dataItem.DisplayIndex == ContactsListView.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("TitlesList"); 

     // 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); 

    } 
    } 
}