How do call this method to bind it to an Infragistics control?

876 Views Asked by At

This method correctly loads the data and binds it to the infragistics control as long as I remove the object source, EventArgs e and call the method from page_load.

Is that a good idea to remove the object source, eventArgs e?

protected void dgvAppts_NeedDataSource(object source, EventArgs e)
        {
            if (Session.IsNewSession == false)
            {
                DataTable ApptTable = new DataTable();
                ApptTable = objGatewayFunctions.GetAppointmentReCap(Session["LoginID"].ToString(), RecapDate.ToShortDateString(), "R", ConfigurationManager.AppSettings["Connection"].ToString());
                this.dgvAppts.DataSource = ApptTable;
                //if (ApptTable.Rows.Count == 0)
                //{
                //    this.uwtTabs.Tabs(0).Style.ForeColor = System.Drawing.Color.Gray;
                //}
                //else
                //{
                //    this.uwtTabs.Tabs(0).Style.ForeColor = System.Drawing.Color.Black;
                //}
            }
        }

If it's better to have the object source, EventArgs e present in the method. How do I call that function so it can load the WebDataGrid?

2

There are 2 best solutions below

1
On BEST ANSWER

I don't think Infragistics WebDataGrid has NeedDataSource event; it sounds like the code was being converted from the use of a Telerik control.

If that's the case then there's no need to call the method

protected void dgvAppts_NeedDataSource(object source, EventArgs e)

You can call it instead something like

protected void BindMyGrid()

and call it from the page load indeed (with possible check to do it only if page is not in a postback mode)

2
On

You need to assign your method as event handler to NeedDataSource event in your grid control.

Select your grid in the designer, open Properties window and select your method as event handler for NeedDataSource event.

Looks like the method got detached from the event and that's why you have to call it yourself. It should be the grid control that calls your method when it needs the data source by raising the event.