Hi,
How do I populate a DropDownList that is within a EditItemTemplate? I have tried to use the following code -
PayBandDropDownList.items.insert(0,"A Test Item")
But I get a NullException error. Basically I want to add a list of items that are from a database. I can't hard code these items in my asp page using "<asp:ListItem>" since these items may change in the database at a later date.
Here is a *some* of my code:
<asp:TemplateColumn HeaderText="Pay Band">
<ItemTemplate>
<asp:Label runat="server" Width="100"
Text='<%# DataBinder.Eval(Container.DataItem, "PayBand") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp
ropDownList runat="server"
SelectedIndex='<%# GetPayBandIndex(Container.DataItem("PayBand")) %>'
id="edit_payband">
(These hard coded list items would be removed.)
<asp:listitem>BAND1</asp:listitem> <asp:listitem>BAND2</asp:listitem>
<asp:listitem>BAND3</asp:listitem>
<asp:listitem>BAND4</asp:listitem>
<asp:listitem>BAND5</asp:listitem>
<asp:listitem>BAND6</asp:listitem>
<asp:listitem>BAND7</asp:listitem>
<asp:listitem>BAND8</asp:listitem>
<asp:listitem>BAND9</asp:listitem>
<asp:listitem>BNDC1</asp:listitem>
<asp:listitem>BNDC2</asp:listitem>
<asp:listitem>BNDC3</asp:listitem>
<asp:listitem>BNDC4</asp:listitem>
<asp:listitem>BNDC5</asp:listitem>
<asp:listitem>BNDC6</asp:listitem>
</asp:dropdownlist>
</EditItemTemplate>
</asp:TemplateColumn>
Public Function GetPayBandIndex(PayBand As String) As Integer
If PayBandIndex(PayBand) <> Nothing
Return CInt(PayBandIndex(PayBand))
Else
Return 0
End If
End Function
Sub emp_list_EditCommand(s As Object, e As DataGridCommandEventArgs)
emp_list.EditItemIndex = e.Item.ItemIndex
Dim PayBandDropDownList As DropDownList = e.Item.FindControl("edit_payband")
PayBandDropDownList.items.insert(0,"A Test Item")
BindData
End Sub
Any suggestions? Thanks.
How do I populate a DropDownList that is within a EditItemTemplate? I have tried to use the following code -
PayBandDropDownList.items.insert(0,"A Test Item")
But I get a NullException error. Basically I want to add a list of items that are from a database. I can't hard code these items in my asp page using "<asp:ListItem>" since these items may change in the database at a later date.
Here is a *some* of my code:
<asp:TemplateColumn HeaderText="Pay Band">
<ItemTemplate>
<asp:Label runat="server" Width="100"
Text='<%# DataBinder.Eval(Container.DataItem, "PayBand") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp

SelectedIndex='<%# GetPayBandIndex(Container.DataItem("PayBand")) %>'
id="edit_payband">
(These hard coded list items would be removed.)
<asp:listitem>BAND1</asp:listitem> <asp:listitem>BAND2</asp:listitem>
<asp:listitem>BAND3</asp:listitem>
<asp:listitem>BAND4</asp:listitem>
<asp:listitem>BAND5</asp:listitem>
<asp:listitem>BAND6</asp:listitem>
<asp:listitem>BAND7</asp:listitem>
<asp:listitem>BAND8</asp:listitem>
<asp:listitem>BAND9</asp:listitem>
<asp:listitem>BNDC1</asp:listitem>
<asp:listitem>BNDC2</asp:listitem>
<asp:listitem>BNDC3</asp:listitem>
<asp:listitem>BNDC4</asp:listitem>
<asp:listitem>BNDC5</asp:listitem>
<asp:listitem>BNDC6</asp:listitem>
</asp:dropdownlist>
</EditItemTemplate>
</asp:TemplateColumn>
Public Function GetPayBandIndex(PayBand As String) As Integer
If PayBandIndex(PayBand) <> Nothing
Return CInt(PayBandIndex(PayBand))
Else
Return 0
End If
End Function
Sub emp_list_EditCommand(s As Object, e As DataGridCommandEventArgs)
emp_list.EditItemIndex = e.Item.ItemIndex
Dim PayBandDropDownList As DropDownList = e.Item.FindControl("edit_payband")
PayBandDropDownList.items.insert(0,"A Test Item")
BindData
End Sub
Any suggestions? Thanks.
Comment