Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Bind complex data to control in ListView (class User contain instance of class UserType)
    primarykey
    data
    text
    <p>I have 2 value class</p> <pre><code>public class UserType { public int ID; public string TypeName; } public class User { public int ID; public string UserName; public UserType Type; } </code></pre> <p>1 proccessing class</p> <pre><code>public class Users { public User[] GetUsers() { //Retrive and re turn User array } public int Update(User user, User old_user) { //Update user } } </code></pre> <p>1 ListView and 1 ObjectDataSource</p> <pre><code>&lt;asp:ListView ID="lsvUser" runat="server" DataKeyNames="ID" DataSourceID="odsUser" ItemPlaceholderID="plhItem" onitemupdating="lsvUser_ItemUpdating"&gt; &lt;LayoutTemplate&gt; &lt;ul&gt;&lt;asp:PlaceHolder ID="plhItem" runat="server"&gt;&lt;/asp:PlaceHolder&gt;&lt;/ul&gt; &lt;/LayoutTemplate&gt; &lt;ItemTemplate&gt; &lt;li&gt; &lt;asp:Label ID="lblID" runat="server" Text='&lt;%# Eval("ID") %&gt;'&gt;&lt;/asp:Label&gt; &lt;asp:Label ID="lblUserName" runat="server" Text='&lt;%# Eval("UserName") %&gt;'&gt;&lt;/asp:Label&gt; &lt;asp:Label ID="lblTypeName" runat="server" Text='&lt;%# Eval("Type.TypeName") %&gt;'&gt;&lt;/asp:Label&gt; &lt;asp:LinkButton ID="btEdit" runat="server" CssClass="button" CommandName="Edit" Text="Edit"&gt;&lt;/asp:LinkButton&gt; &lt;/li&gt; &lt;/ItemTemplate&gt; &lt;EditItemTemplate&gt; &lt;li class="editRow"&gt; &lt;asp:Textbox ID="txbUserName" runat="server" Text='&lt;%# Bind("UserName") %&gt;'&gt;&lt;/asp:Textbox &gt; &lt;asp:Textbox ID="txbTypeName" runat="server" Text='&lt;%# Bind("Type.TypeName") %&gt;'&gt;&lt;/asp:Textbox &gt; &lt;/li&gt; &lt;/EditItemTemplate&gt; &lt;/asp:ListView&gt; &lt;asp:ObjectDataSource ID="odsUser" runat="server" TypeName="BLL.Users" DataObjectTypeName="BLL.User" SelectMethod="GetUsers" UpdateMethod="Update" ConflictDetection="CompareAllValues" OldValuesParameterFormatString="old_{0}"&gt;&lt;/asp:ObjectDataSource&gt; </code></pre> <p>When data is loaded into the ItemTemplate, the ListView interprets Type.TypeName and binds correctly, but when updating the record, I cannot retrieve the old_user.Type from the old values. So old_user.Name and old_user.ID have values but old_user.Type is null.</p> <p>Help me. I have been searching for about 2 days and cannot find a solution. I can bind data for a new user like this:</p> <pre><code>protected void lsvUser_ItemUpdating(object sender, ListViewUpdateEventArgs e) { e.NewValues.Add("Type", new BLL.UserType() { TypeName = Convert.ToString(((TextBox)lsvUser.EditItem.FindControl("txbTypeName")).Text) }); } </code></pre> <p>But I don't know how to retrieve the old values (how to retrive value of lblTypeName). Help me. If there is a solution that doesn't require additional code in the ItemUpdating event, please teach me.</p> <p>Thank you.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload