DropDownList in side the DetailsView
I am very new to dotnet 2.0 and I need alot of help. In the DetailsView EditItemTemplate I have a dropdownlist which i have problem with when I click on the Update button. The error message that I got is:
"'DropDownList2' has a SelectedValue which is invalid because it does not exist in the list of items. Parameter name: value ".
If I leave out the "SelectedValue='<%# Bind("") %>" from the tag then the edit mode displayed ok.
Thanks very much,
Loi.
Here is my code:
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
DataKeyNames="iSurveyQuestionid" DataSourceID="SqlDataSource2" Height="50px"
OnItemInserting="DetailsView1_ItemInserting"
OnItemUpdating="DetailsView1_ItemUpdating"
OnDataBound="DetailsView1_DataBound"
CellPadding="4" ForeColor="#333333"
Width="100%">
<Fields>
<asp:BoundField DataField="iSurveyQuestionid" HeaderText="iSurveyQuestionid" InsertVisible="False"
ReadOnly="True" Visible="False" SortExpression="iSurveyQuestionid" />
<asp:TemplateField HeaderText="Physical Question" SortExpression="vchPhysicalQuestion">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Text='<%# Bind("vchPhysicalQuestion") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" TextMode="MultiLine" Text='<%# Bind("vchPhysicalQuestion") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("vchPhysicalQuestion") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle Width="20%" />
</asp:TemplateField>
<asp:TemplateField HeaderText="chQuestionType" SortExpression="chQuestionType">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" SelectedValue='<%# Bind("chQuestionType") %>'>
<asp:ListItem Value="S">Single</asp:ListItem>
<asp:ListItem Value="M">Multiple</asp:ListItem>
<asp:ListItem Value="T">Text</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList3" runat="server" SelectedValue='<%# Bind("chQuestionType") %>'>
<asp:ListItem Value="S">Single</asp:ListItem>
<asp:ListItem Value="M">Multiple</asp:ListItem>
<asp:ListItem Value="T">Text</asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("chQuestionType") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField Visible="False" DataField="iSurveyid" HeaderText="iSurveyid" SortExpression="iSurveyid" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
The label displayed the value of "S" when I first load the page.
|