Solved

filtering gridview

Posted on 2008-10-13
3
293 Views
Last Modified: 2010-04-21
I have an existing gridview i want to filter. below is the sql data source. I want to filter by a drop down (for board_id) and text box (for date).

how would i write the code to bind the gridview with the filters? do I use the datasource.filterparameters?

<asp:SqlDataSource ID="myDataSourceDay" runat="server" 

        CacheDuration="300" ConnectionString="<%$ ConnectionStrings:real_time_chartingConnectionString4 %>"

				EnableCaching="True"            

        

        

        SelectCommand="SELECT Actual_Data.datestamp, Actual_Data.Actual_ID, Actual_Data.Actual_Qty, Actual_Data.Target_Qty, TB_Time.Time_Desc, Actual_Data.Board_ID, Actual_Data.Run_Date, Actual_Data.datestamp AS Expr1, TB_Time.Time_Shift, TB_Comment.Comment_Desc, Actual_Data.Comment_ID FROM Actual_Data INNER JOIN TB_Time ON Actual_Data.Time_ID = TB_Time.Time_ID INNER JOIN TB_Comment ON Actual_Data.Comment_ID = TB_Comment.Comment_ID WHERE (Actual_Data.Board_ID = @board_id) AND (Actual_Data.Run_Date &gt; @datestamp) AND (Actual_Data.Run_Date &lt;= @datestamp2) AND (TB_Time.Time_Shift = N'day')" 

        

        

        

        UpdateCommand="UPDATE Actual_Data SET Actual_Qty =@Actual_Qty, Comment_ID = @Comment_ID WHERE (Actual_ID = @Actual_ID)">

                 <SelectParameters>

                     <asp:SessionParameter DefaultValue="1" Name="board_id" 

                         SessionField="board_id" />                    

                     <asp:SessionParameter DefaultValue="7/1/2008" Name="datestamp" 

                         SessionField="currentDate" Type="DateTime" />

                     <asp:SessionParameter DefaultValue="7/1/2008" Name="datestamp2" 

                         SessionField="currentDate2" Type="DateTime" />

               </SelectParameters>

			     <UpdateParameters>                     

                       <asp:ControlParameter ControlID="GridView1" DefaultValue="0" Name="Actual_Qty" 

                           PropertyName="SelectedValue" />

                            <asp:ControlParameter ControlID="GridView1" DefaultValue="0" Name="Comment_ID" 

                           PropertyName="SelectedValue" />

                       <asp:Parameter Name="Actual_ID" />

                 </UpdateParameters>

			</asp:SqlDataSource>

Open in new window

0
Comment
Question by:sassy168
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
crumber earned 500 total points
ID: 22707530
Create a select parameter on the sqldatasource that is a control parameter for the dropdownlistbox.
I usually have a stored procedure as the result set for the select sqldatasource, where i use the input parameter as the filter and then include it in the sql (inside the stored proc).
The autopostback should be set to true for the dropdownlistbox and when the user changes the selection, the gridview is requeried using the value from the dropdown.
It works great.
Let me know.
0
 

Author Comment

by:sassy168
ID: 22713322
i have created the parameters on the sqldatasouce for both control and form items. HOwever, the gridview doesn'tdisplay any data. do i need to bind the data with code perhaps? i want to filter with a button.
0
 

Author Closing Comment

by:sassy168
ID: 31505723
i got it, thanks :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Response.Redirect Open new Form/tab/page? 5 30
Why is "packages element is not declared"? 2 132
Calling stored proc in EDMX 11 23
Authentication of Web Services 3 53
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now