Todd Penland
asked on
ASP.NET Web Form: Unable to Resolve Error in Template Field
I have an ASP.NET web form that is throwing an error I can't seem to work out. I have confirmed that all of the data sources are working as expected however the item template and the edit template in the template field within the datagrid causes the error with the following message:
Message:
'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
Stack Trace:
at System.Web.UI.WebControls. ListContro l.PerformD ataBinding (IEnumerab le dataSource) at System.Web.UI.WebControls. ListContro l.OnDataBi nding(Even tArgs e) at System.Web.UI.WebControls. ListContro l.PerformS elect() at System.Web.UI.WebControls. BaseDataBo undControl .DataBind( ) at System.Web.UI.Control.Data BindChildr en() at System.Web.UI.Control.Data Bind(Boole an raiseOnDataBinding) at System.Web.UI.Control.Data Bind() at System.Web.UI.Control.Data BindChildr en() at System.Web.UI.Control.Data Bind(Boole an raiseOnDataBinding) at System.Web.UI.Control.Data Bind() at System.Web.UI.WebControls. GridView.C reateRow(I nt32 rowIndex, Int32 dataSourceIndex, DataControlRowType rowType, DataControlRowState rowState, Boolean dataBind, Object dataItem, DataControlField[] fields, TableRowCollection rows, PagedDataSource pagedDataSource) at System.Web.UI.WebControls. GridView.C reateChild Controls(I Enumerable dataSource, Boolean dataBinding) at System.Web.UI.WebControls. CompositeD ataBoundCo ntrol.Perf ormDataBin ding(IEnum erable data) at System.Web.UI.WebControls. GridView.P erformData Binding(IE numerable data) at System.Web.UI.WebControls. DataBoundC ontrol.OnD ataSourceV iewSelectC allback(IE numerable data) at System.Web.UI.DataSourceVi ew.Select( DataSource SelectArgu ments arguments, DataSourceViewSelectCallba ck callback) at System.Web.UI.WebControls. DataBoundC ontrol.Per formSelect () at System.Web.UI.WebControls. BaseDataBo undControl .DataBind( ) at System.Web.UI.WebControls. GridView.D ataBind() at System.Web.UI.WebControls. BaseDataBo undControl .EnsureDat aBound() at System.Web.UI.WebControls. CompositeD ataBoundCo ntrol.Crea teChildCon trols() at System.Web.UI.Control.Ensu reChildCon trols() at System.Web.UI.Control.PreR enderRecur siveIntern al() at System.Web.UI.Control.PreR enderRecur siveIntern al() at System.Web.UI.Control.PreR enderRecur siveIntern al() at System.Web.UI.Control.PreR enderRecur siveIntern al() at System.Web.UI.Control.PreR enderRecur siveIntern al() at System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt)
Query String
Can anyone help me identify the problem?
Page:
Sample Schedule Data:
Message:
'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value
Stack Trace:
at System.Web.UI.WebControls.
Query String
Can anyone help me identify the problem?
Page:
<%@ Page Title="Edit Schedule" Language="C#" MasterPageFile="~/MasterPages/Main.master" AutoEventWireup="true" CodeFile="ScheduleEdit.aspx.cs" Inherits="Management_Group_ScheduleEdit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="cpHC" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpMC" Runat="Server">
<h2>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>: Edit Schedule</h2>
<asp:GridView ID="gvEditSchedule" runat="server" AutoGenerateColumns="False" AutoGenerateEditButton="True" DataKeyNames="Id" DataSourceID="dsScheduleEdit">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" InsertVisible="False" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="IntervalStartDate" HeaderText="Start Date" SortExpression="IntervalStartDate" ReadOnly="True" />
<asp:BoundField DataField="TeamNumber" HeaderText="Team No" SortExpression="TeamNumber" ReadOnly="True" />
<asp:TemplateField HeaderText="Participant" SortExpression="Participant">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="dsMembers" DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("Participant") %>'>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="dsMembers" DataTextField="Name" DataValueField="Id" SelectedValue='<%# Bind("Participant") %>'>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="dsScheduleEdit" runat="server" ConnectionString="<%$ ConnectionStrings:dbCS %>" SelectCommand="SELECT * FROM [Schedule] WHERE (([IntervalStartDate] >= @IntervalStartDate) AND ([IntervalStartDate] <= @IntervalStartDate2)) ORDER BY [IntervalStartDate], [TeamNumber], [Participant]">
<SelectParameters>
<asp:SessionParameter Name="IntervalStartDate" SessionField="SearchStartDate" Type="DateTime" />
<asp:SessionParameter Name="IntervalStartDate2" SessionField="SearchEndDate" Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="dsMembers" runat="server" ConnectionString="<%$ ConnectionStrings:dbCS %>" SelectCommand="spClientGroupMemberSortNames" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:SessionParameter Name="GroupID" SessionField="GroupID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
Sample Schedule Data:
ASKER
Thanks for the reply. I know that's what the error means, but when I check the value of the session variable (GroupID) that serves as the parameter for the dsMembers DataSource it has the correct value, and when I manually execute the stored procedure that supplies the data for that DataSource using that parameter it returns the correct data. It is not possible (in my database design) for a Participant value to exist in the Schedule table that doesn't also exist in the Members table. The problem I'm currently having is that I don't know how to see what (if anything) the stored procedure is returning in real time. Any ideas? Thanks!
EDIT: I forgot to mention that I was using vS Express 2013 for Web so if there's a tool in there (or elsewhere) that will allow me to see what data the stored procedure is returning in real time, I'm not aware of it.
EDIT: I forgot to mention that I was using vS Express 2013 for Web so if there's a tool in there (or elsewhere) that will allow me to see what data the stored procedure is returning in real time, I'm not aware of it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
When you click Edit, the item Which you are trying to set as DropDownList SelectedValue = Participant, that ID is not present in the DropDownList items.