我在编辑字段中有一个下拉列表为“ddVehicleType”。我在页面加载时从数据库中获取价值。但错误来了
'ddVehicleType' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: value
我的编码是,
while (reader.Read())
{
ddVehicleType.SelectedValue = reader["VehicleId"].ToString();
}
设计页面,
<asp:DropDownList ID="ddVehicleType" runat="server" AppendDataBoundItems="true" CssClass="drop" DataSourceID="SqlDataSource2" DataTextField="VehicleType" DataValueField="VehicleId">
<asp:ListItem Value="0">-Select-</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TAXIConnectionString %>" SelectCommand="SELECT [VehicleId], [VehicleType] FROM [VehicleMaster] WHERE ([Status] = @Status)">
<SelectParameters>
<asp:Parameter DefaultValue="Available" Name="Status" Type="String" />
</SelectParameters>
</asp:SqlDataSource>