E
et
I don't understand why this always happens, what am I doing wrong?
I have a grid:
<asp:datagrid id=dg runat="server" AutoGenerateColumns="False">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete"
CommandName="Delete"></asp:ButtonColumn>
<asp:BoundColumn Visible="true" DataField="ID"
ReadOnly="True"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Class Number">
<ItemTemplate>
<%#Container.DataItem("ClassNumber")%>
</ItemTemplate>
<EditItemTemplate>
<aspropDownList runat="server" ID="Dropdownlist1"/>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
Then I have the ItemDataBound event:
If e.Item.ItemType = ListItemType.EditItem Then
Dim ddl As DropDownList = CType(e.Item.Cells(3).Controls(0),
DropDownList)
ddl.Items.Add("Item1")
ddl.Items.Add("Item2")
...
End If
and it always errs on the cast line:
Dim ddl As DropDownList = CType(e.Item.Cells(3).Controls(0),
DropDownList)
Exception Details: System.ArgumentOutOfRangeException: Specified
argument was out of the range of valid values. Parameter name: index
Even though I know it's cell 3, and control 0, I have tried putting 1, 2, 3,
4, 5 for the cell index and the control index. It doesn't make sense, what
am I missing?
I have a grid:
<asp:datagrid id=dg runat="server" AutoGenerateColumns="False">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update"
CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete"
CommandName="Delete"></asp:ButtonColumn>
<asp:BoundColumn Visible="true" DataField="ID"
ReadOnly="True"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Class Number">
<ItemTemplate>
<%#Container.DataItem("ClassNumber")%>
</ItemTemplate>
<EditItemTemplate>
<aspropDownList runat="server" ID="Dropdownlist1"/>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
Then I have the ItemDataBound event:
If e.Item.ItemType = ListItemType.EditItem Then
Dim ddl As DropDownList = CType(e.Item.Cells(3).Controls(0),
DropDownList)
ddl.Items.Add("Item1")
ddl.Items.Add("Item2")
...
End If
and it always errs on the cast line:
Dim ddl As DropDownList = CType(e.Item.Cells(3).Controls(0),
DropDownList)
Exception Details: System.ArgumentOutOfRangeException: Specified
argument was out of the range of valid values. Parameter name: index
Even though I know it's cell 3, and control 0, I have tried putting 1, 2, 3,
4, 5 for the cell index and the control index. It doesn't make sense, what
am I missing?