error with RowDataBound but not with RowCreated
Hi,
Can someone explain me why the same code with the event
GridView1_RowDataBound gives this error:
'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value
and not with the event GridView1_RowCreated ?
In normal mode, everything is shown correcly, but when i click on the Edit button in the gridview, the error happens.
Thanks
H.
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 dd As DropDownList
Dim i As Integer
Dim z As ListItem
dd = e.Row.FindControl("DropDownList1")
For i = 1 To 20
z = New ListItem(i, i)
dd.Items.Add(z)
Next
End If
End If
End Sub
aspx file:
---------
<asp:TemplateField>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" Width="90px" SelectedValue='<%# Bind("wa") %>' >
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("wa") %'> </asp:Label>
</ItemTemplate>
</asp:TemplateField>
|