Click here to Skip to main content
15,030,781 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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...

What I have tried:

<asp:GridView ID="gridUserAccounts" runat="server"  AllowPaging="True" AllowSorting="True" CssClass="GridMain" AutoGenerateColumns="False" DataSourceID="UserAccounts_DS"
                            AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" GridLines="None" DataKeyNames="UserId">
                            <alternatingrowstyle backcolor="#ffffff" />
                            <rowstyle cssclass="GridRow" />
                            <HeaderStyle ForeColor="#ffffff" CssClass="GridHeader" />
                            <footerstyle cssclass="GridHeader" />
                            <pagerstyle forecolor="#ffffff" backcolor="#003366" />
                                <asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
                                <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                                <asp:CheckBoxField DataField="IsApproved" HeaderText="Approved"/>
                                <asp:TemplateField HeaderText="Approved" SortExpression="Approved" />
                                <asp:TemplateField HeaderText="Role Name">
                                    <asp:DropDownList ID="ddlRole" runat="server" DataSourceID="UserAccounts_DS" DataTextField="RoleName" DataValueField="RoleId" SelectedValue='<%# Bind("RoleId") %>' >

                                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("RoleName") %>'>

This is the code I'm changing it to:

<asp:DropDownList ID="ddlRole" DataTextField="RoleId" DataValueField="RoleId" runat="server" AutoPostBack="False">
                            <asp:ListItem Text="NFI" Value="NFI">
                            <asp:ListItem Text="Partner" Value="Partner">
                            <asp:ListItem Text="Customer" Value="Customer">
Updated 12-Jun-16 19:58pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900