Simple TypedList and Binding to Web DataGrid

Posts   
 
    
Wade
User
Posts: 76
Joined: 15-Jun-2004
# Posted on: 14-Apr-2005 18:42:04   

I know this is probably simple, but I am having no luck. I have created a test web project and hooked in the DLLs for my llblgen generated DAL. I have also included the SD.LLBGenPro.... DLLs. I added the Typed Lists to my Toolbox in the IDE. I did a drag and drop to the web page. I added a simple datagrid to the page. Now all I want to do is to load the grid with my data from the list. What am I doing wrong? Here is the code section from the web page:


    public class WebForm1 : System.Web.UI.Page
    {
        protected TMSWebControls.AdvWebGrid AdvWebGrid1;
        protected System.Web.UI.WebControls.DataGrid DataGrid1;
        protected SolutionDesigners.Data.VTMAG.TypedListClasses.ListWebClickLogsTypedList listWebClickLogsTypedList1; 
    
        private void Page_Load(object sender, System.EventArgs e)
        {

            // Put user code to initialize the page here
            DataAccessAdapter da = new DataAccessAdapter();
            DataTable dt = new DataTable();

            da.FetchTypedList( listWebClickLogsTypedList1.GetFieldsInfo(), dt, null );

            
            
            int returnCount = listWebClickLogsTypedList1.Count;
            DataGrid1.DataBind();

        
        }

        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {   
            this.listWebClickLogsTypedList1 = new SolutionDesigners.Data.VTMAG.TypedListClasses.ListWebClickLogsTypedList();
            ((System.ComponentModel.ISupportInitialize)(this.listWebClickLogsTypedList1)).BeginInit();
            // 
            // listWebClickLogsTypedList1
            // 
            this.listWebClickLogsTypedList1.ObeyWeakRelations = false;
            this.listWebClickLogsTypedList1.TableName = "ListWebClickLogs";
            this.Load += new System.EventHandler(this.Page_Load);
            ((System.ComponentModel.ISupportInitialize)(this.listWebClickLogsTypedList1)).EndInit();

        }
        #endregion
    }
}


Thanks, Wade

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39614
Joined: 17-Aug-2003
# Posted on: 15-Apr-2005 10:20:36   

This routine is weird:


        private void Page_Load(object sender, System.EventArgs e)
        {

            // Put user code to initialize the page here
            DataAccessAdapter da = new DataAccessAdapter();
            DataTable dt = new DataTable();

            da.FetchTypedList( listWebClickLogsTypedList1.GetFieldsInfo(), dt, null );

            
            
            int returnCount = listWebClickLogsTypedList1.Count;
            DataGrid1.DataBind();

        
        }

because, you're fetching the data into a NEW datatable, while you have already defined a typedlist object. Furthermore, the DataGrid1.DataSource property isn't set.

So change the routine above into:


        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            DataAccessAdapter da = new DataAccessAdapter();

            da.FetchTypedList( listWebClickLogsTypedList1.GetFieldsInfo(), listWebClickLogsTypedList1, listWebClickLogsTypedList1.GetRelationInfo() );
            
            int returnCount = listWebClickLogsTypedList1.Count;
            DataGrid1.DataSource = listWebClickLogsTypedList1;
            DataGrid1.DataBind();
        }

Frans Bouma | Lead developer LLBLGen Pro