DropDownList的里面EditItemTemplate中 [英] DropDownList inside EditItemTemplate
问题描述
我使用的是EditTemplate这样内的下拉列表:
I am using a dropdown within an EditTemplate as such:
<EditItemTemplate>
<asp:DropDownList ID="ddlBusinessType" runat="server" DataSourceID="BusinessTypeSource" DataTextField="Value" DataValueField="Value" AppendDataBoundItems="true" Text='<%# Bind("BusinessType") %>'>
<asp:ListItem>Please Select</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
数据源具有以下值:
The DataSource has the following value:
Personal
Professional
这是我遇到的问题是,我结合领域有着空白值。
作为空值是不是在数据源我得到以下错误信息:
The problem that I am running into is that the field that I am binding has a blank value. As a blank value is not in the DataSource I get the following error message:
<青霉>'ddlBusinessType'具有的SelectedValue,因为它不在项目列表中存在这是无效的。参数名称:值的
不知道如何解决这个问题。当我做我的绑定,如果值是不是在数据源,我喜欢它默认为请选择
Not sure how to fix this. When I do my binding, if the value is not in the datasource, I like to default it to 'Please Select'
推荐答案
视情况而定,但一个选项,我会经常使用时间如下:
Depends on the circumstances, but one option I'll use often times is as follows:
1)在查找表,我将有标题为未选择的条目,
0的主键值(或其他)。
1) In the lookup table, I'll have an entry titled 'Not Selected', with a primary key value of 0 (or whatever).
2)在事务表,更新所有该字段的空值0(或任何值是你的'未选择选项)。此外,该字段的缺省值设置为0。
2) In the transaction table, update all of the null values for that field to 0 (or whatever the value is for your 'Not Selected' option). Also, set the default value of that field to 0.
这是一对夫妇的原因尼斯 - 之一,不需要特殊的加价(所以你知道这将始终是一致的) - 和两个,哪里的其他的使用这些数据,你将有机会获得未选择输出。
This is nice for a couple of reasons -- one, no special mark-up required (so you know it will always be consistent) -- and two, wherever else you use this data, you'll have access to the 'not selected' output.
这篇关于DropDownList的里面EditItemTemplate中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!