C
Chris
Hi,
i defined a dropdownlist in the EditTemplate of a gridview like this:
<asp:TemplateField HeaderText="min" SortExpression="min">
<EditItemTemplate>
<aspropDownList ID="DropDownList1" runat="server" SelectedValue='<%#
Bind("min") %>' >
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("min") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Now i want to populate that dropdownlist programmatically because the values
go from 0 to 2OO (it would be fastidious to do that manually).
I tried this in code-behind (vb.net)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim gv As GridView
Dim dd As DropDownList
Dim z As ListItem
Dim i As Integer
gv = form1.FindControl("gridview1")
dd = gv.FindControl("dropdownlist1")
If Not Page.IsPostBack Then
For i = 0 To 200
z = New ListItem(i, i)
dd.Items.Add(z)
Next
End If
End Sub
But this gives this error at runtime: "Object reference not set to an
instance of an object."
at line: dd.Items.Add(z)
What's wrong in my code? I could do this with succes when the dropdownlist
was just in Form1 and not in a template.
Thanks for help
Chris
i defined a dropdownlist in the EditTemplate of a gridview like this:
<asp:TemplateField HeaderText="min" SortExpression="min">
<EditItemTemplate>
<aspropDownList ID="DropDownList1" runat="server" SelectedValue='<%#
Bind("min") %>' >
</aspropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("min") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Now i want to populate that dropdownlist programmatically because the values
go from 0 to 2OO (it would be fastidious to do that manually).
I tried this in code-behind (vb.net)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim gv As GridView
Dim dd As DropDownList
Dim z As ListItem
Dim i As Integer
gv = form1.FindControl("gridview1")
dd = gv.FindControl("dropdownlist1")
If Not Page.IsPostBack Then
For i = 0 To 200
z = New ListItem(i, i)
dd.Items.Add(z)
Next
End If
End Sub
But this gives this error at runtime: "Object reference not set to an
instance of an object."
at line: dd.Items.Add(z)
What's wrong in my code? I could do this with succes when the dropdownlist
was just in Form1 and not in a template.
Thanks for help
Chris