Advertise with us

ListView DropDownList Edit ListView

Posted by  Ankita Pandey
 1454  View(s)
Rate this:

I have created a ListView that has editing enabled, the wizard generated the table with the use of textboxes but i require the use of dropdown lists for some options.

I have created the dropdown list

 <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>

The drop down list generates successfully but doesn't submit and enter itself in the databse.

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

The above snippet needs to used somewhere in order to bind the data but which parameter does it need attaching to to pass the data?

I've tried everything and its giving me a right headache!


  1. Re: ListView DropDownList Edit ListView

    Hi Ankita, 

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

      Modified On Apr-04-2018 06:35:23 AM