DropDownList1'有一个无效的SelectedValue [英] DropDownList1' has a SelectedValue which is invalid

查看:55
本文介绍了DropDownList1'有一个无效的SelectedValue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




i动态提供一个从1到20的下拉列表。那个
下拉列表绑定到字段''wa''(类型nvarchar (4))''mytable''。

是4条记录,字段''wa''的值是:2 3 1 4.所有这些值

包含在DD的项目列表中。

在正常模式下,每个记录都会显示正确值的字段''wa'。

当我点击编辑按钮时,我收到此错误:


" DropDownList1''有一个SelectedValue无效,因为它没有

项目列表中存在。

参数名称:value


页面的EnableViewState属性=" true"

< asp:TemplateField>

< EditItemTemplate>

< asp:DropDownList ID =" DropDownList1" RUNAT = QUOT;服务器" SelectedValue =''<%#

Bind(" wa")%>''>

< / asp:DropDownList>

< / EditItemTemplate>

< ItemTemplate>

< asp:Label ID =" Label2" RUNAT = QUOT;服务器" Text =''<%#Bind(" wa")%>''>< / asp:标签>

< / ItemTemplate>

< / asp:TemplateField>

受保护的子GridView1_RowDataBound(ByVal发送者为对象,ByVal e As

System.Web.UI.WebControls.GridViewRowEventArgs)处理

GridView1.RowDataBound


如果(e.Row.RowState和DataControlRowState.Edit)= DataControlRowState.Edit

那么

如果e.Row.RowType = DataControlRowType.DataRow那么


Dim i As Integer

Dim z作为ListItem

Dim dd As DropDownList


dd = e.Row.FindControl(" DropDownList1")

for i = 1 to 20

z =新ListItem(i.ToString,i.ToString)

dd.Items.Add(z)

下一页

结束如果

结束如果


end sub

Hi,

i dynamically feed a dropdownlist which value from 1 to 20. That
dropdownlist is bound to field ''wa'' (type nvarchar(4)) in ''mytable''. There
are 4 records and the values of field ''wa'' are: 2 3 1 4. All those values
are contained in the list of items of the DD.
In normal mode, the field ''wa'' appears for each record with the right value.
When i click on the Edit button, i get this error:

"DropDownList1'' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value

The EnableViewState property of the page ="true"

<asp:TemplateField>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue=''<%#
Bind("wa") %>''>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text=''<%# Bind("wa") %>''></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound

If (e.Row.RowState And DataControlRowState.Edit) = DataControlRowState.Edit
Then
If e.Row.RowType = DataControlRowType.DataRow Then

Dim i As Integer
Dim z As ListItem
Dim dd As DropDownList

dd = e.Row.FindControl("DropDownList1")
For i = 1 To 20
z = New ListItem(i.ToString, i.ToString)
dd.Items.Add(z)
Next
End If
End If

end sub

推荐答案

在ItemDataBound事件期间,您需要添加存储的文本&因为它不在你想要创建的列表中,所以这个值是由于列表控件所需要的是



我可以在VB中给你一个例子,如果有帮助的话


John

" Ben" < be*@nol.vbwrote in message

news:%2 **************** @ TK2MSFTNGP03.phx.gbl ...
During the ItemDataBound Event you need to add the stored text & value to
the DD because it is not in the list you are trying to create, which is
requied by the list control.

I can give you an example in VB if it would help

John
"Ben" <be*@nol.vbwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...




i动态提供一个从1到20的下拉列表。那个

下拉列表被绑定在''mytable''中字段''wa''(类型nvarchar(4))。

是4条记录,字段''wa''的值是:2 3 1 4.所有这些值

包含在DD的项目列表中。

在普通模式下,每个记录都会显示字段''wa''

值。

当我点击编辑按钮,我收到此错误:


DropDownList1具有一个无效的SelectedValue,因为它没有项目列表中存在的


参数名称:value


页面的EnableViewState属性=" true"


< EditItemTemplate>

< asp:DropDownList ID =" DropDownList1" RUNAT = QUOT;服务器" SelectedValue =''<%#

Bind(" wa")%>''>

< / asp:DropDownList>

< / EditItemTemplate>

< ItemTemplate>

< asp:Label ID =" Label2" RUNAT = QUOT;服务器" Text =''<%#Bind(" wa")

%>''>< / asp:标签>

< / ItemTemplate>

< / asp:TemplateField>


受保护的子GridView1_RowDataBound(ByVal发送者为对象,ByVal e As

System.Web .UI.WebControls.GridViewRowEventArgs)句柄

GridView1.RowDataBound


If(e.Row.RowState和DataControlRowState.Edit)=

DataControlRowState.Edit然后

如果e.Row.RowType = DataControlRowType.DataRow那么


Dim i As Integer

Dim z作为ListItem

Dim dd As DropDownList

dd = e.Row.FindControl(" DropDownList1")

For i = 1到20

dd.Items.Add(z)

下一步

结束如果

结束如果


end sub
Hi,

i dynamically feed a dropdownlist which value from 1 to 20. That
dropdownlist is bound to field ''wa'' (type nvarchar(4)) in ''mytable''. There
are 4 records and the values of field ''wa'' are: 2 3 1 4. All those values
are contained in the list of items of the DD.
In normal mode, the field ''wa'' appears for each record with the right
value.
When i click on the Edit button, i get this error:

"DropDownList1'' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value

The EnableViewState property of the page ="true"

<asp:TemplateField>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue=''<%#
Bind("wa") %>''>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text=''<%# Bind("wa")
%>''></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound

If (e.Row.RowState And DataControlRowState.Edit) =
DataControlRowState.Edit Then
If e.Row.RowType = DataControlRowType.DataRow Then

Dim i As Integer
Dim z As ListItem
Dim dd As DropDownList

dd = e.Row.FindControl("DropDownList1")
For i = 1 To 20
z = New ListItem(i.ToString, i.ToString)
dd.Items.Add(z)
Next
End If
End If

end sub



感谢您的回复。

我找不到ItemDataBound事件,只有RowDataBound,DataBound和

RowCreated。


如果你有一个例子,那就没事了......


约翰 < no*@non.comschreef in bericht

新闻:O7 ************** @ TK2MSFTNGP05.phx.gbl ...
Thanks for your reply.
I can''t find the ItemDataBound event, only RowDataBound, DataBound and
RowCreated.

If you have an example, it would be fine ...

"John" <no*@non.comschreef in bericht
news:O7**************@TK2MSFTNGP05.phx.gbl...

在ItemDataBound事件期间,您需要添加存储的文本&因为它不在你想要创建的列表中,所以这个值是由于列表控件所需要的是



我可以在VB中给你一个例子,如果有帮助的话


John

" Ben" < be*@nol.vbwrote in message

news:%2 **************** @ TK2MSFTNGP03.phx.gbl ...
During the ItemDataBound Event you need to add the stored text & value to
the DD because it is not in the list you are trying to create, which is
requied by the list control.

I can give you an example in VB if it would help

John
"Ben" <be*@nol.vbwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...

>
我动态地提供一个从1到20的下拉列表。那个
下拉列表绑定到字段''wa ''(类型nvarchar(4))在''mytable''中。
有4条记录,字段''wa''的值是:2 3 1 4.所有这些值都包含在内在DD的项目列表中。
在正常模式下,每个记录的字段wa都会显示正确的
值。
当我点击编辑按钮时,我得到此错误:

DropDownList1具有一个无效的SelectedValue,因为它没有存在于项目列表中。
参数名称:值

页面的EnableViewState属性=" true"
< asp:TemplateField>
< EditItemTemplate>
< asp:DropDownList ID =" DropDownList1" RUNAT = QUOT;服务器" SelectedValue =''<%#
Bind(" wa")%>''>
< / asp:DropDownList>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =" Label2" RUNAT = QUOT;服务器" Text =''<%#Bind(" wa")
%>''>< / asp:Label>
< / ItemTemplate>
< / asp :TemplateField>

受保护的子GridView1_RowDataBound(ByVal发送者为对象,ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs)句柄
GridView1.RowDataBound

if(e.Row.RowState和DataControlRowState.Edit)=
DataControlRowState.Edit然后
如果e.Row.RowType = DataControlRowType.DataRow那么

Dim i As整数
Dim z作为ListItem
Dim dd As DropDownList

dd = e.Row.FindControl(" DropDownList1")
对于i = 1到20
z = New ListItem(i.ToString,i.ToString)
dd.Items.Add(z)
下一页
结束如果
结束如果

end sub
>Hi,

i dynamically feed a dropdownlist which value from 1 to 20. That
dropdownlist is bound to field ''wa'' (type nvarchar(4)) in ''mytable''.
There are 4 records and the values of field ''wa'' are: 2 3 1 4. All those
values are contained in the list of items of the DD.
In normal mode, the field ''wa'' appears for each record with the right
value.
When i click on the Edit button, i get this error:

"DropDownList1'' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value

The EnableViewState property of the page ="true"

<asp:TemplateField>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue=''<%#
Bind("wa") %>''>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text=''<%# Bind("wa")
%>''></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridView1.RowDataBound

If (e.Row.RowState And DataControlRowState.Edit) =
DataControlRowState.Edit Then
If e.Row.RowType = DataControlRowType.DataRow Then

Dim i As Integer
Dim z As ListItem
Dim dd As DropDownList

dd = e.Row.FindControl("DropDownList1")
For i = 1 To 20
z = New ListItem(i.ToString, i.ToString)
dd.Items.Add(z)
Next
End If
End If

end sub




我的错误,我的想法是在Listview而不是GridView RowDataBound是正确的,但是

这个想法是一样的,我所做的就是在编辑模板上添加一个隐藏的字段

即绑定到源。然后我使用findcontrol得到它的值ex。

HF.Value,然后首先添加它使用dd.SelectedText.Value,我得到奇数

结果与dd.SelectedValue,有时它不会接受它。


然后在你的for中如果你想要的话,过滤出HF值,这样就不会两次列出




试一试

约翰


" Ben" < be*@nol.vbwrote in message

news:ua ************** @ TK2MSFTNGP05.phx.gbl ...
My error, my mind was on Listview not GridView RowDataBound is correct, but
the idea is the same, what I do is add a hidden field to the edit template
that is bound to the source. Then I use findcontrol to get it''s value ex.
HF.Value, then add it first to using dd.SelectedText.Value, I get odd
results with dd.SelectedValue, somtimes it won''t take it.

Then in your "for" filter out the HF value if you want to so it is not in
the list twice.

Give it a try
John

"Ben" <be*@nol.vbwrote in message
news:ua**************@TK2MSFTNGP05.phx.gbl...

感谢您的回复。

我找不到ItemDataBound事件,只有RowDataBound,DataBound和

RowCreated。


如果你有一个例子,那就没事了......


" John" < no*@non.comschreef in bericht

新闻:O7 ************** @ TK2MSFTNGP05.phx.gbl ...
Thanks for your reply.
I can''t find the ItemDataBound event, only RowDataBound, DataBound and
RowCreated.

If you have an example, it would be fine ...

"John" <no*@non.comschreef in bericht
news:O7**************@TK2MSFTNGP05.phx.gbl...

>在ItemDataBound事件期间,您需要添加存储的文本&因为它不在你想要创建的列表中,因为它不在列表控件所需的列表中。

我可以在VB中给你一个例子它会有所帮助

John
Ben < be*@nol.vbwrote in message
新闻:%2 **************** @ TK2MSFTNGP03.phx.gbl ...
>During the ItemDataBound Event you need to add the stored text & value to
the DD because it is not in the list you are trying to create, which is
requied by the list control.

I can give you an example in VB if it would help

John
"Ben" <be*@nol.vbwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...

>>
我动态地提供一个从1到20的下拉列表。那个
下拉列表绑定到字段''wa'' (在'mytable''中输入nvarchar(4))。
有4条记录,字段''wa''的值是:2 3 1 4.所有这些值都包含在DD的项目列表。
在正常模式下,每个记录的字段''wa''显示正确的
值。
当我点击编辑按钮时,我得到这个错误:

DropDownList1有一个SelectedValue无效,因为它没有存在于项目列表中。
参数名称:值
< asp:TemplateField>
< EditItemTemplate>
< asp:DropDownList ID =" DropDownList1" RUNAT = QUOT;服务器" SelectedValue =''<%#
Bind(" wa")%>''>
< / asp:DropDownList>
< / EditItemTemplate>
< ItemTemplate>
< asp:Label ID =" Label2" RUNAT = QUOT;服务器" Text =''<%#Bind(" wa")
%>''>< / asp:Label>
< / ItemTemplate>
< / asp :TemplateField>

受保护的子GridView1_RowDataBound(ByVal发送者为对象,ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs)句柄
GridView1.RowDataBound

if(e.Row.RowState和DataControlRowState.Edit)=
DataControlRowState.Edit然后
如果e.Row.RowType = DataControlRowType.DataRow那么

Dim i As整数
Dim z作为ListItem
Dim dd As DropDownList

dd = e.Row.FindControl(" DropDownList1")
对于i = 1到20
z = New ListItem(i.ToString,i.ToString)
dd.Items.Add(z)
下一页
结束如果
结束如果

end sub
>>Hi,

i dynamically feed a dropdownlist which value from 1 to 20. That
dropdownlist is bound to field ''wa'' (type nvarchar(4)) in ''mytable''.
There are 4 records and the values of field ''wa'' are: 2 3 1 4. All those
values are contained in the list of items of the DD.
In normal mode, the field ''wa'' appears for each record with the right
value.
When i click on the Edit button, i get this error:

"DropDownList1'' has a SelectedValue which is invalid because it does not
exist in the list of items.
Parameter name: value

The EnableViewState property of the page ="true"

<asp:TemplateField>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue=''<%#
Bind("wa") %>''>
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text=''<%# Bind("wa")
%>''></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs ) Handles
GridView1.RowDataBound

If (e.Row.RowState And DataControlRowState.Edit) =
DataControlRowState.Edit Then
If e.Row.RowType = DataControlRowType.DataRow Then

Dim i As Integer
Dim z As ListItem
Dim dd As DropDownList

dd = e.Row.FindControl("DropDownList1")
For i = 1 To 20
z = New ListItem(i.ToString, i.ToString)
dd.Items.Add(z)
Next
End If
End If

end sub





这篇关于DropDownList1'有一个无效的SelectedValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆