newbieal
asked on
calendar in gridview
How can I add a calendar in a gridview to be used as filtering (start and end date)?
ASKER
I guess I could hide the calendar and only show it if the user clicks on a button?
Also, what if I then need to add additional filtering capabilities, such as dropdown lists?
Also, what if I then need to add additional filtering capabilities, such as dropdown lists?
Its sounds like you are wanting the functionality of AJAX. There is a Calendar control extender that the AJAX control tool kit offers that i believe will give you this functionality. (only showing the calender when the user clicks in a textbox)
Please check out
http://www.asp.net
look at the ajax control toolkit examples for the calender control extender. This site has great tutorial videos that will greatly enhance your site.
if you need additional filtering capabilities on the button click , have the first value in the dropdown list be "ANY" with a value of 0 and if the selected index of the dropdown isn't 0 then concatenate the additonal query to the main query. Check out the example below.(this would be in the button click event
if i wanted to find a certain state and name for a Customer ) Let me know if this is what you're looking for.
Please check out
http://www.asp.net
look at the ajax control toolkit examples for the calender control extender. This site has great tutorial videos that will greatly enhance your site.
if you need additional filtering capabilities on the button click , have the first value in the dropdown list be "ANY" with a value of 0 and if the selected index of the dropdown isn't 0 then concatenate the additonal query to the main query. Check out the example below.(this would be in the button click event
if i wanted to find a certain state and name for a Customer ) Let me know if this is what you're looking for.
Dim strQuery as String = "Select * from Customer where "
If ddlState.SelectedIndex <> 0 then
strQuery += " State = '" & ddlState.SelectedItem.ToString & "' "
End If
If ddlCustomerNames.SelectedIndex <> 0 then
strQuery += " And CustomerName = '" & ddlCustomerName.SelectedItem.ToString & "' "
End If
Dim sqlConnection As New SqlConnection("Your connection string here")
Dim cmdSql As SqlCommand = New SqlCommand(sqlConnection.ConnectionString)
cmdSql.CommandType = CommandType.text
'This will set the command text to proper query
cmdSql.CommandText = strQuery
ASKER
i wish I had access to AJAx but I don't so I'm left with asp and vb, unfortuanatly. I'm looking more for something I can mostly code in asp .net via filter or select parameters.
I just want the user to be able to select values from the 2 dropdowns and the calendar and the gridview filter accordingly. Meaning if dropdownlist1 has been selected the gridview should filter accordingly if then dropdownlist2 has been changed then it should filter further and so on with the date range/ calendar as well. But if let's say dropdownlist1 has been changed back to index of 0 (meaning 'select a value from the list') then the gridview should at least still be filtering from the current settings for dropdownlist2, etc. but it doesn't do that right now.
Thanks for all of your help and patience!
I just want the user to be able to select values from the 2 dropdowns and the calendar and the gridview filter accordingly. Meaning if dropdownlist1 has been selected the gridview should filter accordingly if then dropdownlist2 has been changed then it should filter further and so on with the date range/ calendar as well. But if let's say dropdownlist1 has been changed back to index of 0 (meaning 'select a value from the list') then the gridview should at least still be filtering from the current settings for dropdownlist2, etc. but it doesn't do that right now.
Thanks for all of your help and patience!
its no problem.
it just sounds like you need to have some logic to give you the results that you wish to have. (Similair to last code example i gave ) you'll have be testing both values together and both values apart each time in your IF statements.
if this doesn't help just tell me exactly what you're doing and i can assist with a sample project.
it just sounds like you need to have some logic to give you the results that you wish to have. (Similair to last code example i gave ) you'll have be testing both values together and both values apart each time in your IF statements.
if this doesn't help just tell me exactly what you're doing and i can assist with a sample project.
If ddlState.SelectedIndex <> 0 then
strQuery += " State = '" & ddlState.SelectedItem.ToString & "' "
End If
If ddlCustomerNames.SelectedIndex <> 0 then
strQuery += " And CustomerName = '" & ddlCustomerName.SelectedItem.ToString & "' "
End If
ASKER
Here is as far as I've gotten. I haven't even yet attempted to add the calendar control yet. I just want to get the filtering down properly. The issue is that when the first dropdownlist is selected, index 1 is selected, it does not filter properly for that value, but when the second value, index 2 is selected, filtering is fine. There is also some discrepency between dropdownlist1.index1.selec ted and dropdownlist2.index1orinde x2.selecte d. Sometimes the filtering seems to be working and accurate and sometimes it's not. What can the issue be?
SelectCommand="SELECT * FROM [atable] WHERE (([afield] = @afield) OR (@afield IS NULL)) OR (([bfield] = @bfield) OR (@bfield IS NULL))"
CancelSelectOnNullParameter="False" >
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="afield" PropertyName="SelectedValue"
Type="String" ConvertEmptyStringToNull="True" />
<asp:ControlParameter ControlID="DropDownList2" Name="bfield" PropertyName="SelectedValue"
Type="String" ConvertEmptyStringToNull="True" />
</SelectParameters>
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If DropDownList1.SelectedIndex.Equals(0) And DropDownList2.SelectedIndex.Equals(0) Then
data.SelectCommand = ("SELECT * FROM [atable]")
GridView1.DataBind()
End If
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok, I'll give this a try. I just assumed that the rest of the logic occurred in the aspx page under the select command...will I have to delete this if I implement the above code?
I would just add a new page and put a new gridview on the page and a couple of new dropdownlists and then add the code above to the page load
and Test it that way you will still have the original one to refer to if you need it.
oh and you will need to declare
Dim myDataset as new Dataset
then you should be able to just copy and paste the code
and Test it that way you will still have the original one to refer to if you need it.
oh and you will need to declare
Dim myDataset as new Dataset
then you should be able to just copy and paste the code
ASKER
Ok, I did that but ran into several errors, the latest being: Fill: SelectCommand.Connection property has not been initialized.
for this line of code: myNewDA.Fill(myDataset, "YOURTABLE")
for this line of code: myNewDA.Fill(myDataset, "YOURTABLE")
ASKER
I continued with what I had and added the logic you provided. Thank you so much for helping me!!
ASKER
Thank you for your great patience!!
its no problem . Good luck on the rest of your project !
I have given the button click event code below and also attached both the codebehind and html source files as txt files. i hope this helps
Open in new window
CodeBehind.txtHtmlSource.txt