Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ddl_names' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

this is what i have so far i get the above error




<%--Headings for Product info--%>



<asp:ListView ID="ListView1" runat="server" onitemdatabound="ListView1_ItemDataBound">
<itemtemplate>


Name DescriptionPrice  
<asp:HiddenField ID="hdf_idE" runat="server" Value ='<%#Eval ("id") %>' />
<asp:DropDownList ID="ddl_names" runat="server" Text='<%#Bind ("productName") %>' />
<asp:Button ID="btn_update" runat="server" Text="Update" CommandName ="Update" ValidationGroup="update" />
<asp:Button ID="btn_delete" runat="server" Text="Delete" CommandName="Delete" OnClientClick="return confirm('Confirm Delete?');" />
<asp:Button ID="btn_cancel" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="false"/>

<%--Buttons for insert and cancel, delete --%>


public partial class _Default : System.Web.UI.Page
{
private void _subRebind()
{

//create new instance of the the DataContext class that we have just created

productsDataContext db = new productsDataContext();

FillListView(db);


}

private void FillListView(productsDataContext db)
{

//LINQ syntax

//Select the ProductID and ProductName from Products

var allProducts = from c in db.products

select new

{

Id = c.Id,

ProductName = c.productName,

ProductDesc = c.productDesc,

ProductPrice = c.productPrice,

};


if (allProducts.Any())
{
ListView1.DataSource = allProducts;
ListView1.DataBind();
}
else
{
}
}


protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
using (var db = new productsDataContext())
{
var allProducts = from c in db.products

select new

{

Id = c.Id,

ProductName = c.productName,

ProductDesc = c.productDesc,

ProductPrice = c.productPrice,

};


DropDownList ddlNames = (DropDownList)e.Item.FindControl("ddl_names");
if (ddlNames != null)
{
foreach (var item in allProducts)
{

if (item.ProductName != null)
{
ddlNames.Items.Add(new ListItem("productDesc", "productName"));
}

}
}
_subRebind();


//Bind the ListView



}
}

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack) // Shows if the page is visited for the first time
{
_subRebind();
}

}


}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900