Reusing Controls and Binding them to Different DataSource at Run time

Reusing Controls and Binding them to Different DataSource at Run time

Old forum URL: forums.lhotka.net/forums/t/2135.aspx


Inquistive_Mind posted on Friday, January 12, 2007

Hello,

         How can I bind the controls to different CSLA Datasources based on different events at run time.For Example.I have say 5 buttons and  DataGrid .How can I bind 5 different datasources to the same grid based on the click event of each button?Is it possible to do so?

Thanks

V

RockfordLhotka replied on Friday, January 12, 2007

Windows or web?

Inquistive_Mind replied on Monday, January 15, 2007

Sorry about that Rocky,

Its a web application.C# based.

RockfordLhotka replied on Tuesday, January 16, 2007

So you want to click a button and show data set A, then click a different button to see data set B?

Remember that it is your code that returns the data to the CslaDataSource in the SelectObject event handler. So when the user clicks on a button, you could simply load a form-level field with the data to be displayed and then call DataBind() on the grid control to force it to refresh.

The SelectObject event will be raised due to your DataBind() call on the grid control. In your event handler, you can just return the data that was already loaded by the button click event handler:

  e.BusinessObject = _dataToDisplay;

 

Inquistive_Mind replied on Wednesday, January 17, 2007

Thanks a Lot Rocky, but I could not get it to work completely.

                The DataSource does get bound to the Datagrid on the click event of the button but for some reason I have to click the button twice.On the first click only one row is displayed in the grid and on the second click all the rows get displayed.Something to do with refreshing the grid datasource???

               I am attaching the code here...

 

protected void dsWorkOrderList_SelectObject(object sender, Csla.Web.SelectObjectArgs e)

{       e.BusinessObject = .WorkOrderList.Get(Convert.ToInt32(Session["fid"])); }

protected void dsWorkOrderSearchList_SelectObject(object sender, Csla.Web.SelectObjectArgs e)

{ e.BusinessObject = WorkOrderListOnMyShops.Get(Convert.ToInt32(Session["fid"])); }

protected void btnMyShop_Click(object sender, EventArgs e)

{  

            WebGrid1.DataMember = "Default";

            WebGrid1.DataSourceID = "dsWorkOrderSearchList";

            WebGrid1.DataBind();

}

protected void btnMyWO_Click(object sender, EventArgs e)

{

              WebGrid1.DataMember = "Default";

              WebGrid1.DataSourceID = "dsWorkOrderList";

              WebGrid1.DataBind();

}

By default the grid contains some rows when the page is loaded first.

Im new to ASP.Net and CSLA kindly ignore my coding standards but please do let me know if there are better ways of implementing the same.

 Thanks In Advance

V

Copyright (c) Marimer LLC