Hi Trapulo,
Welcome to the MSDN newsgroup.
As for the DetailsView/ObjectDataSource binding problem. I think currentlly
due to the limitation of the "Bind" expression, we can not direclty make
the <%# Bind() %> expression refrence a nested property in the DataObject
like direct property. Based on my research, what we have are the following
two means to workaround the problem:
1. Make our DataObject expose another direct public property which can be
used by the "bind" expression instead of the nested class property.
2. We use "Eval" expression to read the data in ItemTemplate and
EditTemplate, however, for updating, we need to register the DetailsView's
"ItemUpdating" event and manually add the nested property's parameter into
the Parameter collection so as to suit the Update Method's parameter
requirement. For example, we have the following DetailsView, the "Category"
property of the data object is a class type which contains another property
(CategoryID).
======================================
<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True"
DataSourceID="ObjectDataSource1"
Height="50px" Width="125px" AutoGenerateRows="False"
OnItemUpdating="DetailsView1_ItemUpdating">
<Fields>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="Category">
<EditItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="SqlDataSource1"
DataTextField="CategoryName"
DataValueField="CategoryID" SelectedValue='<%# Eval("Category.CategoryID")
%>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%#
Bind("Category") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1"
DataTextField="CategoryName"
DataValueField="CategoryID" SelectedValue='<%# Eval("Category.CategoryID")
%>'>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
=====================================
We use the "Eval" expression to display the Nested property. And manually
use the ItemUpdating event to Add the argument into the parameter
collection like below:(you need to extract the value from DetailsView's
certain row and cell instead of using the hard code value in my case)
===========================
protected void DetailsView1_ItemUpdating(object sender,
DetailsViewUpdateEventArgs e)
{
foreach (string key in e.NewValues.Keys)
{
Response.Write("<br>" + key + ": " + e.NewValues[key]);
}
//
e.NewValues.Add("Category", 3);
}
============================
Hope this helps.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no
rights.)