如果没有,则Dropdownlist绑定null valuee [英] Dropdownlist bound null valuee if there is nothing
问题描述
所以我有问题我在Gridview中有下拉列表首先我需要传递它,如果有人编辑它并给予它值,它将在这里更新是代码片段
So i have question i have dropdownlist in Gridview soo first i need to pass it nothing if someon edit it and gave him value it will update here is code snippet
<asp:DropDownList runat="server" ID="compn" CssClass="Dropdowni" SelectedValue='<%# Bind("Company_ID") %>'
DataSourceID="ObjectDataSource5" DataTextField="Name_Ge"
DataValueField="Code5" Enabled="false"
</asp:DropDownList>
'compn' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
这是错误给出的错误
我尝试过:
here is the error what it is giving mee
What I have tried:
AppendDataBoundItems="true">
<asp:ListItem Text="Select One" Value=""></asp:ListItem>
</asp:DropDownList>
这里是我试过的但是当我进行编辑时它显示我只在db中选择一个我有一些记录
here is what i have tried but when i go on a edit it is showing me only select one in db i have some records
推荐答案
你需要删除``SelectedValue``属性初始加载。
删除以下内容 -
You need to remove the ``SelectedValue`` property from the initial load.
Remove following-
SelectedValue='<%# Bind("Company_ID") %>'
修改后的代码看起来应该像 - br />
The modified code should looks something like-
<asp:dropdownlist runat="server" id="compn" cssclass="Dropdowni" datasourceid="ObjectDataSource5" datatextfield="Name_Ge" datavaluefield="Code5" enabled="false" xmlns:asp="#unknown">
</asp:dropdownlist>
现在,如果你想要选择的东西,你总是可以在后面的代码中做到这一点。
希望,它有帮助:)
辩诉如果您需要进一步的指导,请告诉我。
Now, if you want something to be selected, you can always do that in code behind.
Hope, it helps :)
Please let me know if you need further guidance on this.
这篇关于如果没有,则Dropdownlist绑定null valuee的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!