dataset filter question

G

Guest

I'm trying to filter a dataset on items that are being passed in via a
querystring.

the string looks like this.
chevy|ford|BMW|

on the information page i split the string such as
selCars.split("|")

and i want to filter the dataset based on the string so i do this
dataview.rowfilter ="carmake=" & "'" cars & "'"
datalist.datasource = dv
datalist.databind

now my question is how can i populate and display the datalist for
everything coming in via the querystring and split them correctly at the |?
If I only pass 1 item in such as BMW without the | it works fine, but if i
pass more then 1 and split using | it doesn't work.

my code snippet
for i = 0 to CarArray.Length
dataview.rowfilter ="carmake=" & "'" cars & "'"
next
datalist.datasource = dataview
datalist.databind

i need a table for each item being passed in
 
L

Lucas Tam

for i = 0 to CarArray.Length
dataview.rowfilter ="carmake=" & "'" cars & "'"
next

Shoudl be:

For i = 0 to CarArray.Length -1
If i < CarArray.Length -1 then
dataview.rowfilter = dataview.rowfilter & "carmake=" & "'" cars & "'
AND "
else
dataview.rowfilter = dataview.rowfilter & "carmake=" & "'" cars & "'
end IF
Next
 
G

Guest

Set the rowfilter only one time, using OR to separate your values, e.g.
defaultview.rowfilter = "carmake='chevy' or carmake='ford'"

As written, I presume it only works for the last one in the list.

Bill
 
G

Guest

no matter how i have it it doesn't like the fact that the string is being
split such as
|, or with ^ or anything else of that matter.
if the string looks like this it works
cars.aspx?car=Chevy

if it looks like this it does not work
cars.aspx?cars=chevy|BMW|ford

even if i split it.
 
G

Guest

Which piece doesn't work? Are you saying that when you split that string you
don't get an array with 3 elements? I've not used the pipe character in a
query string, it's possible you need to escape it to send, or use a different
delimiter. Or, if you control both pieces of the app then you could pass the
user's selections via session rather than a query string.

Bill
 
G

Guest

How about something like this?

<%@ Page Language="VB" %>
<script runat="server">

Sub Page_Load(sender As Object, e As EventArgs)
dim strArr() as string
dim selCars as string ="chevy|ford|BMW"
strArr=selCars.split("|")
if not ispostback then
DataList1.datasource=strArr
DataList1.databind()
end if
end sub

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
<asp:DataList id="DataList1" runat="server">
<ItemTemplate>
<asp:Label id="Label1" runat="server"><%#
Container.DataItem %></asp:Label>
</ItemTemplate>
</asp:DataList>
</p>
</form>
</body>
</html>
 
M

Mike

thats what i have and it does't work
it will split the string the the datalist will not populate if there is more
then 1 dataitem in the string.
 
G

Greg Burns

Not sure what the issue here is, but if I would use the IN keyword...

Dim selCars As String = "chevy|ford|BMW"

selCars = "'" & selCars.Replace("|", "','") & "'"

dataview.rowfilter ="carmake IN (" & selCars & ")"

Greg
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top