Home > DeveloperSection > Forums > ListView DropDownList Edit ListView
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    August-23-2014 7:38 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 657  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>

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



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-23-2014 8:43 AM

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

    }

  }

}


Don't want to miss updates? Please click the below button!

Follow MindStick