CodeSmith Community
Your Code. Your Way. Faster!

Help with Binding TList EntityGridView

Latest post 07-02-2007 10:49 AM by mike123. 3 replies.
  • 07-01-2007 7:00 PM

    Help with Binding TList EntityGridView

    Hey guys,

     I am new to nettiers and I would like to knwo the way how to manually bind the TList<Entity> to EntityGridView, I got sorting exception when trying to use this. I saw a post said that TList could not work with EntityGridView, and just wondering that is there any fixed for that. I used TList and Entity gridview so often in my application and I don't want to change entitygridview to standard gridview caused I have to manually write functions for custom paging e.g Records per pages, sorting and selectindex_changed.

     Thank you very much

    Filed under: ,
    • Post Points: 35
  • 07-01-2007 9:08 PM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 734
    • Points 17,040

    Re: Help with Binding TList EntityGridView

     EntityGridView will work with DataSourceControls right now only. Use objectdatasource instead that'll use TList as underline datasource.

    <asp:objectdatasource
              id="ObjectDataSource1"
              runat="server"
              selectmethod="YourMethodThatReturnsTlist"
              typename="NetTiers.DAL" />

    Then in your code-behind, use like following:
    GridView.DataSourceId = ObjectDataSource1;
    GridView.DataBind();

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

    • Post Points: 35
  • 07-01-2007 11:15 PM In reply to

    Re: Help with Binding TList EntityGridView

    Thank for your reply Mike, however what i would like to know is how to bind the TList to objectdatasource at runtime. For example, I have a contact list and search form, I would like to do the search based on criterias e.g. first name, last name, dob. My method  will get those fields and return a TList<Contact>. How can I bind that to my EntityGridView?

    For example I got the function

    protected ecopilot.Entities.TList<ecopilot.Domain.Contacts> GetSearchResults()
    {
       return TList<ecopilot.Domain.Contacts>;
    }

    protected void btnSearch_Click(object sender, EventArgs e)

    {

       ObjectDataSource1.SelectMethod = "GetSearchResults";
       ObjectDataSource1.TypeName =
    "ecopilot.Entities.Contacts";
      GridView1.DataSourceID =
    "ObjectDataSource1";
      GridView1.DataBind();

    }

    I got exception but don't know how to fix this

    ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'GetSearchResults' that has no parameters.

     ObjectDataSource1.TypeName = "ecopilot.Entities.Contacts"; Line 47: GridView1.DataSourceID = "ObjectDataSource1"; Line 48: GridView1.DataBind();

    Could you please help

    • Post Points: 35
  • 07-02-2007 10:49 AM In reply to

    • mike123
    • Top 10 Contributor
    • Joined on 02-25-2005
    • Toronto, Ontario
    • Posts 734
    • Points 17,040

    Re: Help with Binding TList EntityGridView

    I see what you're trying to achive, and think you still can get around with typed datasource along with SqlParameter and its' filter expessions

      <data:ProductsDataSource ID="ProductsDataSource" runat="server" SelectMethod="Find">
          <Parameters>
        <data:SqlParameter Name="Parameters">
         <Filters>
          <data:ProductsFilter  Column="CategoryID" ControlID="__Page" PropertyName="CategoryID" />
         </Filters>
        </data:SqlParameter>
        <data:CustomParameter Name="OrderByClause" Value="" ConvertEmptyStringToNull="false" />
          </Parameters>
      </data:ProductsDataSource>

    Here is how to get ObjectDataSource to work (like you describe, except the objectdagtasource declared on page):


        <asp:ObjectDataSource runat="server" ID="ObjectDataSource"
            TypeName="MyDal.CustomersSearch"
            SelectMethod="GetCustomersByContactName"
            EnablePaging="false" SortParameterName="SortBy"
            >
            <SelectParameters>
                <asp:ControlParameter ControlID="__Page" Name="ContactName" PropertyName="WhereClause" />
                <asp:Parameter Name="SortBy" Direction="input" />
            </SelectParameters>
        </asp:ObjectDataSource>

    code-behind:

        void cmdSearch_Click(object sender, EventArgs e)
        {
            if (txtContactName.Text != string.Empty)
            {
                WhereClause = txtContactName.Text;
                GridView1.DataBind();
            }
        }

        public string WhereClause
        {
            get
            {
                if (ViewState["_whereClause"] != null)
                {
                    return (string)ViewState["_whereClause"];
                }
                return string.Empty;
            }
            set
            {
                ViewState["_whereClause"] = value;
            }
        }

    namespace MyDal
    {
        public class CustomersSearch
        {
            public TList<Customers> GetCustomersByContactName(string ContactName, string SortBy)
            {
                CustomersParameterBuilder searchQuery = new CustomersParameterBuilder();
                searchQuery.Append(CustomersColumn.ContactName, string.Format("{0}*", ContactName));
                TList<Customers> tlist= DataRepository.CustomersProvider.Find(searchQuery.GetParameters());
                tlist.Sort(SortBy);
                return tlist;
            }
        }
    }

     

    see if helps

     

     

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

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