Bind SelectedValue of ASP.net DropDownList to nested property
(first of all, it seems this is a subject that is discussed many times before, but I can't find a proper answer for my case)
I have a asp.net FormView with a DropDownList for the selection of a month. The FormView is data bound to an ObjectDataSource.
<asp:DropDownList ID="MonthsList" DataSourceID="MonthsListDataSource" DataTextField="Value" DataValueField="Key" SelectedValue='<%# Bind("OrderDate.Month") %>' Width="100" runat="server" />
I like to bind the selected value to the nested property 'Month' of 'OrderDate' as shown above. The property OrderDate is of type DateTime. The error开发者_开发百科 I'm getting while binding to a nested property is:
A call to Bind was not well formatted. Please refer to documentation for the correct parameters to Bind.
What is the best solution to be able to bind to a nested propety?
Thanks in advance.
Are you retrieving data from DataSourceID="MonthsListDataSource" and tryingo to bind it to another DataBase field (SelectedValue='<%# Eval("OrderDate.Month") %>') ?
In my application a do this like this:
<asp:DropDownList ID="MonthsList" DataSourceID="MonthsListDataSource" DataTextField="Value" DataValueField="Key" SelectedValue='<%# Eval("MonthsListDataSource.Month") %>' Width="100" runat="server" />
And when Updating a retrieve de DropDownList with find control, get its selected value, associate it to other table (OrderDate.Month) and save it.
Sorry my answer, but i dont know if a undertand it.
What about using Eval keyword
<asp:DropDownList ID="MonthsList" DataSourceID="MonthsListDataSource" DataTextField="Value" DataValueField="Key" SelectedValue='<%# Eval("OrderDate.Month") %>' Width="100" runat="server" />
精彩评论