CodeSmith Community
Your Code. Your Way. Faster!

Not able to Bind with EntityGridView and deeploaded data.

Latest post 04-10-2007 10:40 AM by peelay. 12 replies.
  • 04-06-2007 6:49 PM

    • peelay
    • Top 150 Contributor
    • Joined on 02-12-2006
    • Toronto, Ontario
    • Posts 31
    • Points 870

    Not able to Bind with EntityGridView and deeploaded data.

    Hi there,

    Have tried a number of different suggestions from the forums but can't seem to get this relatively simple setup to work. I'm using the generated web admin templates and just modifying them slightly so that i can editing data from two tables at once. In this sample I'm actually using Aspnet_Users and Aspnet_Membershp tables. I want to be able to edit username/email/password all in same grid item. I can get it to display using eval, but can't get it to bind in the item template. Any suggestions (preferably in the form of sample code hehe) is greatly appreciated!

    <data:EntityGridView ID="GridView1" runat="server"

    AutoGenerateColumns="False"

    OnSelectedIndexChanged="GridView_SelectedIndexChanged"

    DataSourceID="Aspnet_UsersDataSource"

    DataKeyNames="UserId"

    AllowMultiColumnSorting="false"

    AllowPaging="True"

    PageSize="15"

    DefaultSortColumnName=""

    DefaultSortDirection="Ascending"

    ExcelExportFileName="Export_Aspnet_Users.xls"

    CssClass="AdminGridView"

    PagerStyle-CssClass="AdminGridViewFooter"

    ExportToExcelText="Export to Excel"

    >

    <Columns>

    <asp:CommandField ShowSelectButton="True" ShowEditButton="True" />

    <asp:BoundField DataField="UserName" HeaderText="Username" SortExpression="UserName" />

    <asp:BoundField DataField="LoweredUserName" HeaderText="Lowered Username" SortExpression="LoweredUserName" />

     

    <asp:TemplateField HeaderText="Email" SortExpression="Email">

    <ItemTemplate>

    <%# Eval("Aspnet_Membership.Email") %>

    </ItemTemplate>

    <EditItemTemplate>

    <asp:TextBox ID="Email" runat="server" Text='<%# Bind("Aspnet_Membership.Email") %>' />   THIS LINE GIVES ERROR " A call to Bind was not well formatted.  Please refer to documentation for the correct parameters to Bind"

    </EditItemTemplate>

    </asp:TemplateField>

    </Columns>

    <EmptyDataTemplate>

    <b>No users were found in the system!</b>

    </EmptyDataTemplate>

    </data:EntityGridView>

    <data:Aspnet_UsersDataSource ID="Aspnet_UsersDataSource" runat="server"

    SelectMethod="GetPaged"

    EnablePaging="True"

    EnableSorting="True"

    EnableDeepLoad="True"

    >

    <Parameters>

    <data:CustomParameter Name="WhereClause" Value="" ConvertEmptyStringToNull="false" />

    <data:CustomParameter Name="OrderByClause" Value="" ConvertEmptyStringToNull="false" />

    <asp:ControlParameter Name="PageIndex" ControlID="GridView1" PropertyName="PageIndex" Type="Int32" />

    <asp:ControlParameter Name="PageSize" ControlID="GridView1" PropertyName="PageSize" Type="Int32" />

    <data:CustomParameter Name="RecordCount" Value="0" Type="Int32" />

    </Parameters>

    <DeepLoadProperties Method="IncludeChildren" Recursive="false">

    <Types>

    <data:Aspnet_UsersProperty Name="Aspnet_Membership" />

    </Types>

    </DeepLoadProperties>

    </data:Aspnet_UsersDataSource>

     

    • Post Points: 35
  • 04-06-2007 11:10 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: Not able to Bind with EntityGridView and deeploaded data.

    Reply |Contact |Answer

    peelay,

    Seem like nested properties are not supported in two way binding http://forums.asp.net/thread/1213292.aspx 

    Try to extend the business entity by introducing new property like following

    public string MembershipEmail {

     get { return this.Aspnet_Membership.Email; }

    }

    and then specify the MembershipEmail as bind property <asp:TextBox ID="Email" runat="server" Text='<%# Bind("MembershipEmail") %>' />

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 60
  • 04-07-2007 1:40 PM In reply to

    • peelay
    • Top 150 Contributor
    • Joined on 02-12-2006
    • Toronto, Ontario
    • Posts 31
    • Points 870

    Re: Not able to Bind with EntityGridView and deeploaded data.

    Mike,

     Thanks for the prompt reply. Not quite the response I wanted to hear but makes sense at least. I'll go with extending the entities approach.

    Cheers,

    Phill

    • Post Points: 5
  • 04-07-2007 2:19 PM In reply to

    • peelay
    • Top 150 Contributor
    • Joined on 02-12-2006
    • Toronto, Ontario
    • Posts 31
    • Points 870

    Re: Not able to Bind with EntityGridView and deeploaded data.

    Ok, another quick question. Adding Get worked as expected, now my question is, what would the "Set" look like in order to make this field actually update when the row in the EntityGridView is updated? Is that the approach or does it need to be done a different way?

     Thanks again!

    Phill

    • Post Points: 35
  • 04-08-2007 8:51 AM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: Not able to Bind with EntityGridView and deeploaded data.

    That is right, it should be done the same way

    set { this.Aspnet_Membership.Email = value; }

    Typed datasource doesn't support DeepSave method, that needs to be called to persists this value in db. You'd probably need to put some extra logic in the code-behind to accomplish this.

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 04-08-2007 10:12 AM In reply to

    • peelay
    • Top 150 Contributor
    • Joined on 02-12-2006
    • Toronto, Ontario
    • Posts 31
    • Points 870

    Re: Not able to Bind with EntityGridView and deeploaded data.

    I tried this but this.Aspnet_Mebership.Email is null and throws an error.

    But based on what you're saying even if it wasn't null it would actually save anyway right? So in the end afte all this if I understand  you correctly I need to do all the update/edit code manually and can't actually take advantage of the built in functionality of EntiyGridView? Correct?

     Thanks again and happy easter!

    Phill

    • Post Points: 60
  • 04-08-2007 1:42 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: Not able to Bind with EntityGridView and deeploaded data.

    Reply |Contact |Answer

    Phill,

    Take a look here http://community.codesmithtools.com/forums/permalink/16481/16481/ShowThread.aspx#16481

    in your case the getter and setter should look like this actually:

    Aspnet_Users.cs 

            [DescriptionAttribute(""), System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)]
            [DataObjectField(false, false, false)]
            public string MembershipEmail
            {
                get
                {
                    if (Aspnet_Membership == null)
                        return string.Empty;

                    return this.Aspnet_Membership.Email;
                }
                set
                {
                    if (value == null)
                        return;

                    if (Aspnet_Membership == null)
                        Aspnet_Membership = new Aspnet_Membership();

                    this.Aspnet_Membership.Email = value;
                }
            }

    [edit] - i made some correction to the sample above after initial posting [/edit]

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 5
  • 04-09-2007 7:55 AM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: Not able to Bind with EntityGridView and deeploaded data.

    Phill,

    That is right, update needs to be handled manualy, see the snip bellow, it should do the trick: 

    protected void Page_Load(object sender, EventArgs e)

    {

    GridView1.RowUpdated += new GridViewUpdatedEventHandler(GridView1_RowUpdated);

    }

    void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)

    {

    Guid userId = (Guid) e.Keys[0];

    string MembershipEmail = (string)e.NewValues["MembershipEmail"];

    Aspnet_UsersService UserService = new Aspnet_UsersService();

    Aspnet_Users user = UserService.GetByUserId(userId);

     

    UserService.DeepLoad(user, false, DeepLoadType.IncludeChildren, typeof(Aspnet_Membership));

    user.Aspnet_Membership.Email = MembershipEmail;

    UserService.DeepSave(user, DeepSaveType.IncludeChildren, typeof(Aspnet_Membership));

    }

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 04-09-2007 9:28 AM In reply to

    • peelay
    • Top 150 Contributor
    • Joined on 02-12-2006
    • Toronto, Ontario
    • Posts 31
    • Points 870

    Re: Not able to Bind with EntityGridView and deeploaded data.

    Mike,

    Thanks so much for your help on this. Defintely something that I wasn't able to find in the wiki docs! 

    One thing that I found a bit confusing is why in the previous post the DeepSave has to be handled manually. In the "<data:Aspnet_UsersDataSource... " there's actually a parameter called "UpdateMethod" where one of the possible values is "DeepSave". If we have to do this manually is it not working or is it because the EntityGridView doesn't know how to take advantage of the DeepSave option of the DataSource?

    Thanks once again for your help and your work on .netiers.

     Cheers,

    Phill

    • Post Points: 35
  • 04-09-2007 9:50 AM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: Not able to Bind with EntityGridView and deeploaded data.

    Phill,

    Good observation. UpdateMethod="DeepSave" will work! Please disregard the previous approach with void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e) but still requires the extra property in the entity class to wrap around nested property.

    Please let me know if there is any issue.

     

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 04-09-2007 10:14 AM In reply to

    • peelay
    • Top 150 Contributor
    • Joined on 02-12-2006
    • Toronto, Ontario
    • Posts 31
    • Points 870

    Re: Not able to Bind with EntityGridView and deeploaded data.

    Mike,

     I had it working using the void GridView1_RowUpdated....  I checked that UpdateMethod was set to DeepSave and then commented out the line //GridView1.RowUpdated += new GridViewUpdatedEventHandler(GridView1_RowUpdated);  The data was no longer updating which tells me that there's something up with the UpdateMethod="DeepSave" not working. Can you verify?

     Thanks,

    Phill

    • Post Points: 35
  • 04-10-2007 10:30 AM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 726
    • Points 16,910

    Re: Not able to Bind with EntityGridView and deeploaded data.

    Phill,

    Hmm ... it worked for me. Could you verify that you have Bindable attribute?

            [DescriptionAttribute(""), System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)]
            [DataObjectField(false, false, false)]
            public string MembershipEmail
            {
                get
                {
                    if (Aspnet_Membership == null)
                        return string.Empty;

                    return this.Aspnet_Membership.Email;
                }
                set
                {
                    if (value == null)
                        return;

                    if (Aspnet_Membership == null)
                        Aspnet_Membership = new Aspnet_Membership();

                    this.Aspnet_Membership.Email = value;
                }
            }

    Mike Shatny
    --------------------------------------------------------------
    Member of the .netTiers team http://www.nettiers.com
    --------------------------------------------------------------

    • Post Points: 35
  • 04-10-2007 10:40 AM In reply to

    • peelay
    • Top 150 Contributor
    • Joined on 02-12-2006
    • Toronto, Ontario
    • Posts 31
    • Points 870

    Re: Not able to Bind with EntityGridView and deeploaded data.

    Hi Mike,

     Yes I have that attribute. (see code below). I also noticed that when I override UserName, which is part of the base class (no deep saving required). It no longer gets saved unless I do it manually in the GridView1_RowUpdated. Could this be related? Maybe anything that is in the concrete class vs. the base class doesn't get updated by the datasource provider and entitygridview unless done manually?

    Thanks again for your help on this :)

    Here's snippit from Aspnet_Users.cs concrete class:

    /// <summary>

    /// Users membership email address

    /// </summary>

    [System.ComponentModel.DescriptionAttribute(""), System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)]

    [System.ComponentModel.DataObjectField(false, false, false)]

    public override string UserName

    {

    get

    {

    return base.UserName;

    }

    set

    {

    if (base.UserName == value)

    return;

    base.UserName = value;

    if (base.LoweredUserName == value)

    return;

    base.LoweredUserName = value.ToLower();

    }

    }

    /// <summary>

    /// Users membership email address

    /// </summary>

    [System.ComponentModel.DescriptionAttribute(""), System.ComponentModel.Bindable(System.ComponentModel.BindableSupport.Yes)]

    [System.ComponentModel.DataObjectField(false, false, false)]

    public string MembershipEmail

    {

    get

    {

    if (Aspnet_Membership == null)

    return string.Empty;

    return this.Aspnet_Membership.Email;

    }

    set

    {

    if (value == null)

    return;

    if (Aspnet_Membership == null)

    Aspnet_Membership = new Aspnet_Membership();

    this.Aspnet_Membership.Email = value;

    }

    }

    DataSource from .aspx page:

    <data:Aspnet_UsersDataSource ID="Aspnet_UsersDataSource" runat="server"

    SelectMethod="GetPaged"

    EnablePaging="True"

    EnableSorting="True"

    EnableDeepLoad="True"

    UpdateMethod="DeepSave"

    >

    <Parameters>

    <data:CustomParameter Name="WhereClause" Value="" ConvertEmptyStringToNull="false" />

    <data:CustomParameter Name="OrderByClause" Value="" ConvertEmptyStringToNull="false" />

    <asp:ControlParameter Name="PageIndex" ControlID="GridView1" PropertyName="PageIndex" Type="Int32" />

    <asp:ControlParameter Name="PageSize" ControlID="GridView1" PropertyName="PageSize" Type="Int32" />

    <data:CustomParameter Name="RecordCount" Value="0" Type="Int32" />

    </Parameters>

    <DeepLoadProperties Method="IncludeChildren" Recursive="false">

    <Types>

    <data:Aspnet_UsersProperty Name="Aspnet_Membership" />

    </Types>

    </DeepLoadProperties>

    </data:Aspnet_UsersDataSource>

    • Post Points: 5
Page 1 of 1 (13 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems