I have been struggling with this ASP.NET dynamic data problem for several days ... I have a DropDownList containing the table names of all the tables in my data context (.dbml). When I select DropDownList, it should tint the selected table in the GridView. My code works 100% in the MetaTable subclass of GridView (it implements all the rules that I applied in my metaclasses).
However, filtering seems to work if I explicitly add DynamicExpression to the QueryExtender declaration:
<asp:QueryExtender ID="GridQueryExtender" TargetControlID="GridDataSource" runat="server"> <asp:DynamicFilterExpression ControlID="FilterRepeater" /> </asp:QueryExtender>
This, in turn, requires me to explicitly specify MetaTable in LinqDataSource (linqdsData), either programmatically in Page_Load syntax or in ASP.NET syntax.
Since the GridView gets the forests in the Page_Load part of the life cycle, this approach does not work for me, since it takes place in the Page_Init part of the life cycle.
So my requirement is that as soon as I select another table to populate the GridView with DropDownList, the FilterRepeater should reflect the filters of the just selected MetaTable.
Do I have any way to programmatically update FilterRepeater in Page_Load so that it contains the MetaTable filters that I selected in DropDownList.
Below is the code of my code:
ASP.NET Page Code:
protected void Page_Load(object sender, EventArgs e) { if (ddlTable.SelectedIndex > 0) { string tableName = ddlDataType.SelectedValue; linqdsData.TableName = tableName; MetaTable mt = ASP.global_asax.DefaultModel.GetTable(tableName); GridViewData.SetMetaTable(mt, mt.GetColumnValuesFromRoute(Context)); GridViewData.EnableDynamicData(mt.EntityType); GridViewData.DataSourceID = linqdsData.ID; } }
ASP.NET Page:
<asp:Panel runat="server" ID="pnlFilters" CssClass="gridFilterCon" EnableTheming="True"> <div class="filterGridHeading"> Filter the grid by:</div> <asp:QueryableFilterRepeater runat="server" ID="FilterRepeater"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("DisplayName") %>' OnPreRender="Label_PreRender" CssClass="gridFilterLbl" /> <asp:DynamicFilter runat="server" ID="DynamicFilter" /> <br /> </ItemTemplate> </asp:QueryableFilterRepeater> <asp:Button ID="btnFilter" runat="server" Text="OK" EnableTheming="False" UseSubmitBehavior="False" OnClick="btnFilter_Click" /> </asp:Panel> <asp:GridView ID="GridViewData" runat="server" OnSelectedIndexChanged="GridViewData_SelectedIndexChanged" OnPreRender="GridViewData_PreRender" OnRowDataBound="GridViewData_RowDataBound" OnPageIndexChanged="GridViewData_PageIndexChanged" AllowPaging="True" PageSize="50" OnInit="GridViewData_Init"> <Columns> ... </Columns> <PagerTemplate> <asp:GridViewPager ID="GridViewPager1" runat="server" /> </PagerTemplate> <PagerSettings Mode="NumericFirstLast" NextPageText="Next" /> </asp:GridView> <asp:LinqDataSource ID="linqdsData" runat="server" ContextTypeName="pdcDataContext" OnSelected="linqdsData_Selected" OnSelecting="linqdsData_Selecting" EnableUpdate="True"> </asp:LinqDataSource> <asp:QueryExtender ID="GridQueryExtender" TargetControlID="linqdsData" runat="server"> </asp:QueryExtender>
Your help will be greatly appreciated.