Reputation: 1712
I want to filter my gridview by choosing date and time in a dateedit. I put a button which has DataBind() controls. The query of the DataSource of the GridView has a WHERE clause. It has a Control connecting the gridview and the dateedit. When I test the query, it works fine. I enabled ButtonClick event and wrote the following code into that:
protected void ASPxButton2_Click(object sender, EventArgs e)
{
DateEdit.DataBind();
SQLDataSource.DataBind();
ASPxGridView.DataBind();
}
As you can see I bound all stuff that I need. But no items displayed when I choose date and time and click the button. Did I miss something? I appreciate if you help.
Upvotes: 1
Views: 4559
Reputation: 11376
Unfortunately, you did not post the code showing how the SQLDataSource is adjusted. However, I've tried to reproduce this problem and failed. Here is my code:
<dx:ASPxGridView ID="gvSupply" ClientInstanceName="gvSupply" Width="100%"
DataSourceID="SqlDataSource3" KeyFieldName="OrderID" AutoGenerateColumns="False" runat="server">
<Columns>
<dx:GridViewDataTextColumn FieldName="OrderID" ReadOnly="True" VisibleIndex="0">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="CustomerID" VisibleIndex="1">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="EmployeeID" VisibleIndex="2">
</dx:GridViewDataTextColumn>
<dx:GridViewDataDateColumn FieldName="OrderDate" VisibleIndex="3">
</dx:GridViewDataDateColumn>
</Columns>
</dx:ASPxGridView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [Orders] WHERE ([OrderDate] = ?)">
<SelectParameters>
<asp:ControlParameter ControlID="ASPxDateEdit1" Name="OrderDate" PropertyName="Value"
Type="DateTime" />
</SelectParameters>
</asp:SqlDataSource>
<dx:ASPxDateEdit ID="ASPxDateEdit1" runat="server">
</dx:ASPxDateEdit>
<asp:Button ID="Button1" runat="server" Text="Button" />
I've tested the grid with the Orders table from the Northwind database. Also, to test your query, I suggest that you handle the Selecting event of the SQLDataSource and check the e.Command and e.Argumets parameters. I hope, this information will be helpful to you.
Upvotes: 0
Reputation: 848
I'm the DevExpress ASP.NET Technical Evangelist, Mehul.
There are many ways you can approach this but I recommend using the ASPxGridLookup control which gives you a grid within a dropdown: http://demos.devexpress.com/ASPxGridViewDemos/ASPxGridLookup/FilterServerMode.aspx
You can also use the built-in features: http://www.devexpress.com/Support/Center/p/Q267406.aspx Or try this sample: http://www.devexpress.com/Support/Center/e/E2040.aspx
Some of these may help you as well: http://search.devexpress.com/?q=filter+external&p=T4|P5|57
To answer your original question, this sample shows you how to databind on an external button click: http://www.devexpress.com/Support/Center/e/E1662.aspx
Thanks, hope that helps.
Upvotes: 1