By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,386 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

Changing data source

P: n/a
I'm trying to change my datasource of datalist depending of listbox
value:

Listbox:

<asp:DropDownList 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>
</asp:DropDownList><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?

Jun 6 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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" <le*****@yahoo.comwrote in message
news:11*********************@h2g2000hsg.googlegrou ps.com...
I'm trying to change my datasource of datalist depending of listbox
value:

Listbox:

<asp:DropDownList 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>
</asp:DropDownList><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?

Jun 6 '07 #2

P: n/a
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" <le*****@yahoo.comwrote in message
news:11*********************@h2g2000hsg.googlegrou ps.com...
I'm trying to change my datasource of datalist depending of listbox
value:

Listbox:

<asp:DropDownList 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>
</asp:DropDownList><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?

Jun 6 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.