DataBinding and RowFilter

R

Remy De almeida

Hi,
I am working on a test application to get databinding working.
This is the code to bind the data.

System.Data.DataRelation relCustOrd;

System.Data.DataColumn colMaster1;

System.Data.DataColumn colDetail1;

colMaster1 = dsCustomer.Tables["Customers"].Columns["CustomerID"];

colDetail1 = dsCustomer.Tables["Orders"].Columns["CustomerID"];

relCustOrd = new System.Data.DataRelation("RelCustOrd",colMaster1,colDetail1);

dsCustomer.Relations.Add(relCustOrd);


// Grid Databinding

dsCustomer.DefaultViewManager.DataViewSettings["Customers"].RowFilter ="CompanyName like " + "'%" + "b" + "%'" ;

dsView =dsCustomer.DefaultViewManager;

grdOrder.DataSource = dsView;

grdOrder.DataMember = "Customers.RelCustOrd";

This all works fine.... the problem arises when i am using the Row filter or the Sort property after the binding is complete to make a new search. Thus

Problem code:

dsView.DataViewSettings["Customers"].RowFilter ="CompanyName like " + "'%" + "c" + "%'" ;

or

dsView.DataViewSettings["Customers"].Sort ="CompanyName ASC";

Now i thought this should update the bound controls automatically to reflect the new settings of the DefaultViewManager, however this does not happen and the items in the view settings remains the same and hence no change in the data in the bound controls. I even tried clearing all the bindings of the controls and rebinding after the new row filter was applied. Can anyone help?



Cheers,

Remy
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

I will assume that this is a web grid.

The binding is static, it is performed only once, if the datasource change you have to rebind it.

just do:
grdOrder.DataSource = dsView;

grdOrder.DataMember = "Customers.RelCustOrd";

grdOrder.DataBind();


Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Hi,
I am working on a test application to get databinding working.
This is the code to bind the data.

System.Data.DataRelation relCustOrd;

System.Data.DataColumn colMaster1;

System.Data.DataColumn colDetail1;

colMaster1 = dsCustomer.Tables["Customers"].Columns["CustomerID"];

colDetail1 = dsCustomer.Tables["Orders"].Columns["CustomerID"];

relCustOrd = new System.Data.DataRelation("RelCustOrd",colMaster1,colDetail1);

dsCustomer.Relations.Add(relCustOrd);


// Grid Databinding

dsCustomer.DefaultViewManager.DataViewSettings["Customers"].RowFilter ="CompanyName like " + "'%" + "b" + "%'" ;

dsView =dsCustomer.DefaultViewManager;

grdOrder.DataSource = dsView;

grdOrder.DataMember = "Customers.RelCustOrd";

This all works fine.... the problem arises when i am using the Row filter or the Sort property after the binding is complete to make a new search. Thus

Problem code:

dsView.DataViewSettings["Customers"].RowFilter ="CompanyName like " + "'%" + "c" + "%'" ;

or

dsView.DataViewSettings["Customers"].Sort ="CompanyName ASC";

Now i thought this should update the bound controls automatically to reflect the new settings of the DefaultViewManager, however this does not happen and the items in the view settings remains the same and hence no change in the data in the bound controls. I even tried clearing all the bindings of the controls and rebinding after the new row filter was applied. Can anyone help?



Cheers,

Remy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top