J
Jan
Hi,
i defined a dropdownlist in an EditTemplate of a detailsview like this:
<EditItemTemplate>
<aspropDownList ID="drop1" runat="server"></aspropDownList>
</EditItemTemplate>
I want to populate it in code-behind; i tried this:
Protected Sub DetailsView1_ItemCreated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.ItemCreated
If DataControlRowState.Edit Then 'only in edit mode
If DataControlRowType.DataRow Then 'only datarow
Dim dd1 As DropDownList
Dim z1 As ListItem
Dim i As Integer
dd1 = CType(DetailsView1.Rows(5).FindControl("drop1"),
DropDownList)
For i = 0 To 20
z1 = New ListItem(i, i)
dd1.Items.Add(z1)
Next
End If
End If
End Sub
But i get the error:"Object reference not set to an instance of an object"
at line: dd1.Items.Add(z1)
Thanks for help
Jan
i defined a dropdownlist in an EditTemplate of a detailsview like this:
<EditItemTemplate>
<aspropDownList ID="drop1" runat="server"></aspropDownList>
</EditItemTemplate>
I want to populate it in code-behind; i tried this:
Protected Sub DetailsView1_ItemCreated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DetailsView1.ItemCreated
If DataControlRowState.Edit Then 'only in edit mode
If DataControlRowType.DataRow Then 'only datarow
Dim dd1 As DropDownList
Dim z1 As ListItem
Dim i As Integer
dd1 = CType(DetailsView1.Rows(5).FindControl("drop1"),
DropDownList)
For i = 0 To 20
z1 = New ListItem(i, i)
dd1.Items.Add(z1)
Next
End If
End If
End Sub
But i get the error:"Object reference not set to an instance of an object"
at line: dd1.Items.Add(z1)
Thanks for help
Jan