Click here to Skip to main content
14,427,818 members
Rate this:
Please Sign up or sign in to vote.
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 20:58pm

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100