problem when editing with a detailsview


B

Ben

Hi,

i have a detailsview in which i created a dropdownlist which is fed
programmatically.
The field (myfield) in the record contains integer 1.

With If DetailsView1.CurrentMode = DetailsViewMode.Edit, i get the error
(translated):
"selectedValue of myfield is wrong because it doesn't appear in the list
with items"

With If DetailsView1.CurrentMode = DetailsViewMode.Insert, no problem.

Why does i get an error when editing and not when inserting?
Thanks
Ben

<asp:TemplateField>
<EditItemTemplate>
<asp:DropDownList ID="mydd" runat="server" SelectedValue='<%#
Bind("myfield") %>' >
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>

Protected Sub DetailsView1_DataBound(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.DataBound
If DetailsView1.CurrentMode = DetailsViewMode.Edit Then
Dim dvr As DetailsViewRow
Dim dd1 As DropDownList
Dim i As Integer
Dim z As ListItem

For Each dvr In DetailsView1.Rows
dd1 = CType(dvr.FindControl("mydd"), DropDownList)
Next

For i = 1 To 10
z = New ListItem(i, i)
mydd.Items.Add(z)
Next

end if
end sub
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top