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 | Description | Price | |
|
<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();
}
}
}