LISTVIEW DROPDOWNLIST EDIT LISTVIEW

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
 864  View(s)
Ratings:
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>

 </asp:DropDownList>

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!

Thanks

  1. Sumit Kesarwani

    Post:378

    Points:2694
    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);

        }

      }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!