Is it possible for dropdownlist to use a wildcard value. My dropdownlist is bound to a datasource with 3 values (Yes, No, All). The dropdownlist is used by gridview to filter the data. e.g. yes shows only the rows with Yes value in column x. But I need user
to select All value (wildcard) as default so that both Yes and No values appear in the gridview. I did see some code on the interenet and ideas for this but nothing helpful. I want to see if this can be done using the GUI. The gridview GUI has a querystring
option(dont know how to use it) and the gridview allow a where clause to use the dropdown control (this is simple) but how can I get it to use the wildcard (all)?
My dropdownlist is bound to a datasource with 3 values (Yes, No, All). The dropdownlist is used by gridview to filter the data. e.g. yes shows only the rows with Yes value in column x. But I need user to select All value (wildcard) as default so that both
Yes and No values appear in the gridview.
Hi,
If I understand correctly,
you want to filter gridview records with
dropdownlist.
Yes -The link you have looks great - I notice you have field "Username" with "All" value which you add as a listitem in code. When this "All" value is the dropdown list selectedValue then all users will display. This is exactly what I am trying to accomplish.
I checked your code and do not see the statments that actual query the "All" results. Can you explain how you do this and provide example.
All I am trying todo is have a gridview that can be filtered with controls to limit the gridrows for the user. I also need a wildcard (which I cannot seem to code) so that if the user does not use the control to select a value the default value will dislay
all the values for that control.
I have a datasource and would like to have the gridview display data based on user selections in a dropdownlist. Seems simple right!
I created a gridview connected to a datasource and formatted the gridview, the datasource is designed to return all columns. In the gridview GUI I set some of the columns visible=false and dont want user to see them. Then I use the RowDataBound event to
filter the rows based on the user input from the other controls. (e.g. below). If the user does not select a value in the controls then I want to default the value to wildcard. e.g
Protected Sub gv_RowDataBound(ByVal sender as object, ByVal e as System.Web.UI.WebControls.GridviewRowEventArgs) Handles gv.RowDataBound
'Filter Data
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(3).text <> "All" Then
e.row.visible = "True"
Else if e.Row.Cells(3).text == ddl.selectedValue
e.row.visible = "True"
Else
e.row.visible = "False"
End If
End If
End Sub
Is the RowDataBound event best for this filtering?
I wanted to do this from the gv GUI but it only supports boolena matchs and not like matches.
I tried below code and now see "All" in the dropdown as expected but it does not select % all the values in gridview. IN this case the row is a text field with a list of ID's.
Used the GUI to stop throught the gridview Where clause using a control dropdown. At firs the GUI only allows the use of boolean compare like (==, <=,!- etc...). So i completed the GUI using the == operator. Next I went back into the GUI dataConfig and now
there is a screen (using nect) that prompts for "Define Custom Statement or SP" in here I modified the statement and replaced the = operator to a like operator (e.g. Where (id like @id)
Next I added a listItem to the ddl as suggested by Star oned_gk (e.g. <asp:ListItem text=All" Value="%"/>
BINGO!! Now when I select (All option from the ddl all rows are display and when I select a specific id only that id is displayed.
FYI.. I searched many places for this answer with some different responses and not one completely explained or shows the above. I shocked because this seems like a standard thing.
Marked as answer by gogginl on Nov 09, 2012 07:03 PM
gogginl
Member
79 Points
261 Posts
DropdownList and setting a wildcard value to display all values
Nov 07, 2012 03:36 PM|LINK
Is it possible for dropdownlist to use a wildcard value. My dropdownlist is bound to a datasource with 3 values (Yes, No, All). The dropdownlist is used by gridview to filter the data. e.g. yes shows only the rows with Yes value in column x. But I need user to select All value (wildcard) as default so that both Yes and No values appear in the gridview. I did see some code on the interenet and ideas for this but nothing helpful. I want to see if this can be done using the GUI. The gridview GUI has a querystring option(dont know how to use it) and the gridview allow a where clause to use the dropdown control (this is simple) but how can I get it to use the wildcard (all)?
MetalAsp.Net
All-Star
112157 Points
18249 Posts
Moderator
Re: DropdownList and setting a wildcard value to display all values
Nov 07, 2012 05:49 PM|LINK
gogginl
Member
79 Points
261 Posts
Re: DropdownList and setting a wildcard value to display all values
Nov 07, 2012 06:10 PM|LINK
No SQL backend command - just using the Gridview GUI where column like column1 == @column1 and bound to the dropdownlist
gogginl
Member
79 Points
261 Posts
Re: DropdownList and setting a wildcard value to display all values
Nov 07, 2012 07:02 PM|LINK
If the user does not select a dropdown value (dropdownList set as default - say "Select All") I want to have the gridview display all rows
oned_gk
All-Star
31515 Points
6433 Posts
Re: DropdownList and setting a wildcard value to display all values
Nov 08, 2012 01:41 AM|LINK
What is datatype your 'yes' or 'no' field?
If varchar simply
If bit field, Convert bit value to "YES" and "NO" text, and use LIKE condition
And your ddl value is "YES", "NO", and "%"
<asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem>YES</asp:ListItem> <asp:ListItem>NO</asp:ListItem> <asp:ListItem Value="%">ALL</asp:ListItem> </asp:DropDownList>Frank Jiang ...
All-Star
16006 Points
1728 Posts
Microsoft
Re: DropdownList and setting a wildcard value to display all values
Nov 09, 2012 06:39 AM|LINK
Hi,
If I understand correctly, you want to filter gridview records with dropdownlist.
http://www.aspdotnet-suresh.com/2011/11/how-to-filter-gridview-records-with.html
If I have misunderstood your concerns, don't hesitate to let me know.
Feedback to us
Develop and promote your apps in Windows Store
gogginl
Member
79 Points
261 Posts
Re: DropdownList and setting a wildcard value to display all values
Nov 09, 2012 02:55 PM|LINK
Yes -The link you have looks great - I notice you have field "Username" with "All" value which you add as a listitem in code. When this "All" value is the dropdown list selectedValue then all users will display. This is exactly what I am trying to accomplish.
I checked your code and do not see the statments that actual query the "All" results. Can you explain how you do this and provide example.
Thx Larry
gogginl
Member
79 Points
261 Posts
Re: DropdownList and setting a wildcard value to display all values
Nov 09, 2012 05:37 PM|LINK
All I am trying todo is have a gridview that can be filtered with controls to limit the gridrows for the user. I also need a wildcard (which I cannot seem to code) so that if the user does not use the control to select a value the default value will dislay all the values for that control.
I have a datasource and would like to have the gridview display data based on user selections in a dropdownlist. Seems simple right!
I created a gridview connected to a datasource and formatted the gridview, the datasource is designed to return all columns. In the gridview GUI I set some of the columns visible=false and dont want user to see them. Then I use the RowDataBound event to filter the rows based on the user input from the other controls. (e.g. below). If the user does not select a value in the controls then I want to default the value to wildcard. e.g
Protected Sub gv_RowDataBound(ByVal sender as object, ByVal e as System.Web.UI.WebControls.GridviewRowEventArgs) Handles gv.RowDataBound
'Filter Data
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.Cells(3).text <> "All" Then
e.row.visible = "True"
Else if e.Row.Cells(3).text == ddl.selectedValue
e.row.visible = "True"
Else
e.row.visible = "False"
End If
End If
End Sub
Is the RowDataBound event best for this filtering?
I wanted to do this from the gv GUI but it only supports boolena matchs and not like matches.
Going nuts!
gogginl
Member
79 Points
261 Posts
Re: DropdownList and setting a wildcard value to display all values
Nov 09, 2012 06:45 PM|LINK
I tried below code and now see "All" in the dropdown as expected but it does not select % all the values in gridview. IN this case the row is a text field with a list of ID's.
<asp:DropDownList ID="DropDownList1" runat="server"> <asp:ListItem Value="%">ALL</asp:ListItem> </asp:DropDownList>gogginl
Member
79 Points
261 Posts
Re: DropdownList and setting a wildcard value to display all values
Nov 09, 2012 07:03 PM|LINK
OK This is resolved and how it was done!
Used the GUI to stop throught the gridview Where clause using a control dropdown. At firs the GUI only allows the use of boolean compare like (==, <=,!- etc...). So i completed the GUI using the == operator. Next I went back into the GUI dataConfig and now there is a screen (using nect) that prompts for "Define Custom Statement or SP" in here I modified the statement and replaced the = operator to a like operator (e.g. Where (id like @id)
Next I added a listItem to the ddl as suggested by Star oned_gk (e.g. <asp:ListItem text=All" Value="%"/>
BINGO!! Now when I select (All option from the ddl all rows are display and when I select a specific id only that id is displayed.
FYI.. I searched many places for this answer with some different responses and not one completely explained or shows the above. I shocked because this seems like a standard thing.