PC Review


Reply
Thread Tools Rate Thread

Changing data source

 
 
Mirnes
Guest
Posts: n/a
 
      6th Jun 2007
I'm trying to change my datasource of datalist depending of listbox
value:

Listbox:

<aspropDownList ID="ListCriteria" runat="server"
AutoPostBack="True">
<asp:ListItem Selected="True"
Value="1">Positive</asp:ListItem>
<asp:ListItem Value="2">Negative</
asp:ListItem>
<asp:ListItem Value="3">All</asp:ListItem>
</aspropDownList><br />


Function:
Function GetDataSource()

Dim VarDataSource As String
If Me.ListCriteria.SelectedValue = 1 Then
VarDataSource = "SELECT * FROM [CustomerList] WHERE
Amount>0"

ElseIf Me.ListCriteria.SelectedValue = 2 Then
VarDataSource = "SELECT * FROM [CustomerList] WHERE
Amount<0"

Else
VarDataSource = "SELECT * FROM [CustomerList]"

End If

Return VarDataSource
End Function

SelectCommand:

SelectCommand="<%#GetDataSource().ToString()%>"


I don't get any records back. Off course, when I try to do this
manually with criteria from ListBox it works fine.


Any suggestions?

 
Reply With Quote
 
 
 
 
verci
Guest
Posts: n/a
 
      6th Jun 2007
Hi Mirnes,

Your function is not defined correctly, it should be:

Function GetDataSource(ByVal X as Integer) as String
some code
return
End Function


Hope this helps,
Verci

"Mirnes" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm trying to change my datasource of datalist depending of listbox
> value:
>
> Listbox:
>
> <aspropDownList ID="ListCriteria" runat="server"
> AutoPostBack="True">
> <asp:ListItem Selected="True"
> Value="1">Positive</asp:ListItem>
> <asp:ListItem Value="2">Negative</
> asp:ListItem>
> <asp:ListItem Value="3">All</asp:ListItem>
> </aspropDownList><br />
>
>
> Function:
> Function GetDataSource()
>
> Dim VarDataSource As String
> If Me.ListCriteria.SelectedValue = 1 Then
> VarDataSource = "SELECT * FROM [CustomerList] WHERE
> Amount>0"
>
> ElseIf Me.ListCriteria.SelectedValue = 2 Then
> VarDataSource = "SELECT * FROM [CustomerList] WHERE
> Amount<0"
>
> Else
> VarDataSource = "SELECT * FROM [CustomerList]"
>
> End If
>
> Return VarDataSource
> End Function
>
> SelectCommand:
>
> SelectCommand="<%#GetDataSource().ToString()%>"
>
>
> I don't get any records back. Off course, when I try to do this
> manually with criteria from ListBox it works fine.
>
>
> Any suggestions?
>



 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      6th Jun 2007
Just set myDataSource.SelectCommand = GetDataSource() in the codebehind.


--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"Mirnes" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm trying to change my datasource of datalist depending of listbox
> value:
>
> Listbox:
>
> <aspropDownList ID="ListCriteria" runat="server"
> AutoPostBack="True">
> <asp:ListItem Selected="True"
> Value="1">Positive</asp:ListItem>
> <asp:ListItem Value="2">Negative</
> asp:ListItem>
> <asp:ListItem Value="3">All</asp:ListItem>
> </aspropDownList><br />
>
>
> Function:
> Function GetDataSource()
>
> Dim VarDataSource As String
> If Me.ListCriteria.SelectedValue = 1 Then
> VarDataSource = "SELECT * FROM [CustomerList] WHERE
> Amount>0"
>
> ElseIf Me.ListCriteria.SelectedValue = 2 Then
> VarDataSource = "SELECT * FROM [CustomerList] WHERE
> Amount<0"
>
> Else
> VarDataSource = "SELECT * FROM [CustomerList]"
>
> End If
>
> Return VarDataSource
> End Function
>
> SelectCommand:
>
> SelectCommand="<%#GetDataSource().ToString()%>"
>
>
> I don't get any records back. Off course, when I try to do this
> manually with criteria from ListBox it works fine.
>
>
> Any suggestions?
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Data Source nathan_savidge Microsoft Excel Worksheet Functions 1 17th Jul 2008 05:53 PM
Changing Data Source Dave Microsoft Excel Programming 4 22nd Jun 2004 04:31 PM
changing data in a table being used as the data source for an open form Sarah Microsoft Access VBA Modules 1 3rd Feb 2004 10:04 PM
changing the data source name thriveni Microsoft Access Reports 0 13th Jan 2004 03:55 PM
Chart Source Data Ranges Changing when Data Sheet updated from text file source. Tekn0 Microsoft Excel Charting 3 8th Jan 2004 04:45 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:22 PM.