Hi. I'm trying to create a dropdownlist show up when a row is being edited. And the number of items in the dropdownlist depends on the number of rows in the gridview. When i run the code, it's always complaining not being able to reference to the dropdownlist object. Here's the snippet:
Gridview code in the aspx page:
****
<asp:GridView ID="gdvRoles" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="RoleID" DataSourceID="sdsRoles"
OnRowDataBound="gdvContactRoles_RowDataBound">
****
Templatefield in aspx page:
****
<asp:TemplateField HeaderText="Priority" SortExpression="Priority">
<ItemTemplate>
<asp:Label ID="lblRank" runat="server" Text='<%# Eval("rank") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<aspropDownList ID="ddlRank" runat="server"></aspropDownList>
</EditItemTemplate>
</asp:TemplateField>
****
RowDataBound event in aspx.vb page:
****
Protected Sub gdvRoles_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gdvRoles.RowDataBound
Dim i, intCount As Integer
intCount = gdvRoles.Rows.Count
Dim ddlMakeRank As Control
ddlMakeRank = CType(e.Row.Cells(5).FindControl("ddlRank"), DropDownList)
For i = 1 To intCount
ddlMakeRank.Items.Add(New ListItem(i, i))
Next
End Sub
****
Thanks in advance!
NHW
Gridview code in the aspx page:
****
<asp:GridView ID="gdvRoles" runat="server" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="RoleID" DataSourceID="sdsRoles"
OnRowDataBound="gdvContactRoles_RowDataBound">
****
Templatefield in aspx page:
****
<asp:TemplateField HeaderText="Priority" SortExpression="Priority">
<ItemTemplate>
<asp:Label ID="lblRank" runat="server" Text='<%# Eval("rank") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<aspropDownList ID="ddlRank" runat="server"></aspropDownList>
</EditItemTemplate>
</asp:TemplateField>
****
RowDataBound event in aspx.vb page:
****
Protected Sub gdvRoles_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gdvRoles.RowDataBound
Dim i, intCount As Integer
intCount = gdvRoles.Rows.Count
Dim ddlMakeRank As Control
ddlMakeRank = CType(e.Row.Cells(5).FindControl("ddlRank"), DropDownList)
For i = 1 To intCount
ddlMakeRank.Items.Add(New ListItem(i, i))
Next
End Sub
****
Thanks in advance!
NHW