mike

mike

  • NA
  • 23
  • 5.2k

Dropdown list in gridview

Jun 13 2016 3:48 PM
I have a DropDownList in my gridview. I have it set up where it gets populated from the database and I can update the record just fine. But I rather NOT populate it from the database and only give the user 3 choices to choose from. The problem is when I change the code to display the 3 choices to choose from the update to database won't work. Which is a stored procedure and that works good. Below the code the I'm using to populate the DropDownList from my database and how I'm trying to change it to 3 choices to choose from. Can someone please tell me what I'm doing wrong? Thanks...
 
 
<asp:GridView ID="gridUserAccounts" runat="server" DataSourceID="UserAccounts_DS" CssClass="GridMain" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" PageSize="10"
AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" GridLines="None" OnRowDeleting="gridUserAccounts_RowDeleting" OnRowDeleted="gridUserAccounts_RowDeleted" DataKeyNames="UserName, UserId">
<alternatingrowstyle backcolor="#ffffff" />
<rowstyle cssclass="GridRow" />
<HeaderStyle CssClass="GridHeader" ForeColor="#ffffff"/>
<footerstyle cssclass="GridHeader" />
<pagerstyle forecolor="#ffffff" backcolor="#003366" />
<columns>
<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
 
<asp:TemplateField HeaderText="Role Name" SortExpression="RoleName">
<EditItemTemplate> 
<asp:DropDownList ID="ddlRole" runat="server" DataSourceID="UserAccounts_DS" DataTextField="RoleName" DataValueField="RoleId" SelectedValue='<%# Bind("RoleId") %>' >
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("RoleName") %>'></asp:Label>
</ItemTemplate>
 
</asp:TemplateField>
<asp:CheckBoxField DataField="IsApproved" HeaderText="Approved"/>
</columns>
</asp:GridView>
 
 
This is what I'm trying to go to work:
 
 
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="UserAccounts_DS" DataTextField="RoleName" DataValueField="RoleId" SelectedValue='<%# Bind("RoleId") %>' >
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
</asp:DropDownList>

Answers (6)