C# - How to populate a DropDownList in EditItemTemplate

277 views Asked by At

Here, I have a DropDownList in the EditItemTemplate:

<asp:TemplateField HeaderText="RequestedBy" SortExpression="RequestedBy">
                        <EditItemTemplate>
                            <asp:DropDownList ID="ReqUserDDL" runat="server" AppendDataBoundItems ="True" DataSourceID="ReqUsersDataS" DataTextField="Name" DataValueField="Name" SelectedValue='<%# Bind("Name") %>' >
                            </asp:DropDownList>
                            <asp:SqlDataSource ID="ReqUsersDataS" runat="server" ConnectionString="<%$ ConnectionStrings:itassetmgmtConnectionString1 %>" SelectCommand="SELECT Firstname + Lastname AS Name FROM Users"></asp:SqlDataSource>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label7" runat="server" Text='<%# Eval("RequestedBy") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>

However, I keep getting this error:

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'Name'.

Is there a way to remedy this?

1

There are 1 answers

2
Bsa0 On

Use Eval instead of Bind. Bind is for read and/or write, Eval is read-only.

EDIT: Eval/Bind error is not from from the ReqUsersDataS DataSource. It is trying to for a column named 'Name' on the data source of the GridView that has the TemplateField you showed. You just need to make sure that other data source has column named 'Name'.