I'm intrested in filtering the tabels collection on the default.aspx page. The filtering is based on a ID from the data base, selected on a previus page.
my first question is how do i filter the tables by the selected ID?
i have tables that not contain a colum with the selected ID but they have a foreign key table that contains the colum with the selected ID. the question is how can i select the tables based on the selected ID?
protected void Page_Load(object sender, EventArgs e) {
int id = Convert.ToInt32(Session["SelectedID"]);
if (id != 0) {
if (User.Identity.IsAuthenticated && User.IsInRole(RoleEnum.Administrator.ToString())) {
//here i try to select the tables that contain the colum with the id but also i want the filter to select the tables that don't have the colum with the id but have a foreign key with a table that contains the id
System.Collections.IList visibleTables = Global.DefaultModel.VisibleTables.Where(tables => tables.ID == id );
if (visibleTables.Count == 0) {
throw new InvalidOperationException("There are no accessible tables.");
}
Menu1.DataSource = visibleTables;
Menu1.DataBind();
}
else {
Response.Redirect("~/Login.aspx");
}
}
}
yes i know that the VisibleTables doesn't have a property " ID" i was trying too explain what i want to do. i'd like to filter the tables based on a ID that is kept in a table and has relationships with odor tables.
ID_table1
Name
1
Name1
2
Name2
ID_table2
ID_table1
Names
1
1
Name1_1
2
1
Name1_2
3
2
Name2_1
4
2
Name2_2
if i select ID_table1=1 from the first table the second table will be
sorry this is my first post on a forum, next time i'll try to be more specific :)
i'm trying to filter the data displayed on a List page. And I thought that i have to pre filter the tables with the information that i need.
it will be very helpful if you can demonstrate how it's done :)
i know that you can put a filter on the List page. I don't want that, I have a custom filter page, Filter.aspx before the Default.aspx page, after i select the id from the Filter.aspx I redirect to Default.aspx page and i need the information in the tables
( List pages) to be correlated like int the example i gave above
as you can see from the above the FK Column is passed as a value to the List Page pre filtering it try clicking on a children list column to see the effect.
Use Domain Service this makes it real easy to pre filter, but has xome draw backs.
Create a custom filter you add to the QueryExtender, this has limitations
you can only filter the List page not the Drop down list for FK columns etc.
I will take option 2 here:
const string columnName = "CustomerID";
if (Session[columnName] != null)
{
var customExpression = new PropertyExpression();
var parameter = new Parameter(columnName, DbType.Int32, Session[columnName].ToString());
customExpression.Parameters.Add(parameter);
customExpression.SetContext(GridQueryExtender, Context, GridDataSource);
GridQueryExtender.Expressions.Add(customExpression);
}
here it assums you have a parameter you are passing in via session (you could use any means you wish) then adds a Property Expression to the to QueryExtender to pre filter everything.
the default filter on the List page is populated with all the other informations, i want it to be populated only with the id from the customExpression if it's possible can it be applied to the default insert, edit controls on the list page?
i have other tables that not contain the columnName, but they have a relationship with a table that contains the columnName, the filter can be applied to those tables as well?
the default filter on the List page is populated with all the other informations, i want it to be populated only with the id from the customExpression if it's possible can it be applied to the default insert, edit controls on the list page?
This is the more difficule one you have two choices;
Create a custom filter for each FK column that you need this on.
Customise the default FK filter
1 is the easyest but the most work i.e. if you have 10 FK columns in your model that required this then that is ten custom field templates.
JesusUPB
Member
1 Points
4 Posts
How to filter tables on the default.aspx page by id
Jun 05, 2012 11:12 AM|LINK
Hi,
I'm intrested in filtering the tabels collection on the default.aspx page. The filtering is based on a ID from the data base, selected on a previus page.
my first question is how do i filter the tables by the selected ID?
i have tables that not contain a colum with the selected ID but they have a foreign key table that contains the colum with the selected ID. the question is how can i select the tables based on the selected ID?
protected void Page_Load(object sender, EventArgs e) { int id = Convert.ToInt32(Session["SelectedID"]); if (id != 0) { if (User.Identity.IsAuthenticated && User.IsInRole(RoleEnum.Administrator.ToString())) { //here i try to select the tables that contain the colum with the id but also i want the filter to select the tables that don't have the colum with the id but have a foreign key with a table that contains the id System.Collections.IList visibleTables = Global.DefaultModel.VisibleTables.Where(tables => tables.ID == id ); if (visibleTables.Count == 0) { throw new InvalidOperationException("There are no accessible tables."); } Menu1.DataSource = visibleTables; Menu1.DataBind(); } else { Response.Redirect("~/Login.aspx"); } } }any help is most welcome
Regards.
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: How to filter tables on the default.aspx page by id
Jun 05, 2012 11:18 AM|LINK
Sorry JesusUPB, there is no ID property on MetaTable which is what the VisibleTables collections holds?
Always seeking an elegant solution.
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: How to filter tables on the default.aspx page by id
Jun 05, 2012 11:19 AM|LINK
Reading again do you mean you want to pre filter tables based on an ID column?
Always seeking an elegant solution.
JesusUPB
Member
1 Points
4 Posts
Re: How to filter tables on the default.aspx page by id
Jun 05, 2012 11:42 AM|LINK
yes i know that the VisibleTables doesn't have a property " ID" i was trying too explain what i want to do. i'd like to filter the tables based on a ID that is kept in a table and has relationships with odor tables.
ID_table1
Name
1
Name1
2
Name2
ID_table2
ID_table1
Names
1
1
Name1_1
2
1
Name1_2
3
2
Name2_1
4
2
Name2_2
if i select ID_table1=1 from the first table the second table will be
ID_table2
ID_table1
Names
1
1
Name1_1
2
1
Name1_2
Is that possible?
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: How to filter tables on the default.aspx page by id
Jun 05, 2012 11:58 AM|LINK
sorry to appear a little dumb, but are you:
Which ever you are trying to do you can do it, and I will demonstrate how :)
Always seeking an elegant solution.
JesusUPB
Member
1 Points
4 Posts
Re: How to filter tables on the default.aspx page by id
Jun 05, 2012 12:12 PM|LINK
sorry this is my first post on a forum, next time i'll try to be more specific :)
i'm trying to filter the data displayed on a List page. And I thought that i have to pre filter the tables with the information that i need.
it will be very helpful if you can demonstrate how it's done :)
i know that you can put a filter on the List page. I don't want that, I have a custom filter page, Filter.aspx before the Default.aspx page, after i select the id from the Filter.aspx I redirect to Default.aspx page and i need the information in the tables ( List pages) to be correlated like int the example i gave above
thx a lot
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: How to filter tables on the default.aspx page by id
Jun 05, 2012 01:07 PM|LINK
No worries OK I think you have two options (and an extra one when we have .Net 4.5 called Model Binding)
I will take option 2 here:
const string columnName = "CustomerID"; if (Session[columnName] != null) { var customExpression = new PropertyExpression(); var parameter = new Parameter(columnName, DbType.Int32, Session[columnName].ToString()); customExpression.Parameters.Add(parameter); customExpression.SetContext(GridQueryExtender, Context, GridDataSource); GridQueryExtender.Expressions.Add(customExpression); }here it assums you have a parameter you are passing in via session (you could use any means you wish) then adds a Property Expression to the to QueryExtender to pre filter everything.
P.S. see my article here Adding a Multi-Column Search to the Default List page in Dynamic Data (UPDATED)
Always seeking an elegant solution.
JesusUPB
Member
1 Points
4 Posts
Re: How to filter tables on the default.aspx page by id
Jun 06, 2012 08:12 AM|LINK
thx it solved my problem :D
but now i encounter other 2 problems
thx for all your help :D
sjnaughton
All-Star
27308 Points
5458 Posts
MVP
Re: How to filter tables on the default.aspx page by id
Jun 06, 2012 09:50 AM|LINK
This is the more difficule one you have two choices;
1 is the easyest but the most work i.e. if you have 10 FK columns in your model that required this then that is ten custom field templates.
2 is more difficult as you will need to do some generic Linq Expressions see my article here Cascading Filters and Fields – Dynamic Data Entity Framework Version and look particularly at the PopulateListControl method as this could be adapted to achive what you want.
Sorry not sure what you mean in point 2 :(
Always seeking an elegant solution.