473,394 Members | 1,746 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

DropDownList| SqlDataSource | and Parameters??~

Good evening friends,

I have added a Drop Down List box control to my web form. I am using the
web.config connection string to access my SQL Server 2000 db. Inside that
db I have a table named Provinces.

The table contains 3 fields :

LanguageID
ProvinceID
Province

I have also added a SqlDataSource object and configured it to retrieve
Provinces based on my parameter named @languageID

<asp:DropDownList ID="ddlProvince" runat="server"
DataSourceID="ProvSqlDataSource"

DataTextField="province" DataValueField="province" Width="196px">

</asp:DropDownList></td>

<asp:SqlDataSource ID="ProvSqlDataSource" runat="server"
CacheExpirationPolicy="Sliding"

ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"

SelectCommand="SELECT DISTINCT [province] FROM [provinces] WHERE
([languageID] = @languageID ) ORDER BY [province]">

</asp:SqlDataSource>

My problem is how I may gain access to the @languageID parameter. I feel
kinda stoopid, as this may be an easy solution.

It has to change either "1" for English and "2" for French,,,

Depending on the language chosen for the web form page. So I use this code
to retrieve the language chosen by the user.

<%
Dim languageSuffix, altlang, lang As String

Dim langID As Int32

lang = Request.QueryString("lang")
If Request.QueryString("lang") = "" Then

lang = "en"

End If

'Response.Write("<br />The Lang is--" & lang)
If (lang = "fr") Then

langID = 2

altlang = "fr"

Else ' lang = "en"

langID = 1

altlang = "en"

End If
Response.Write(("<br />The LangID is--" & langID))
%>

But I cannot for the life of me figure out how to gain access to the
@languageID and add 1 if English or 2 if French.
Any ideas, code examples or urls would be greatly appreciated,

Thanks in advance

~Brad
Jan 29 '07 #1
2 2438
Brad,

You can manually update your parameters and select the data through code via:

Me.ProvSqlDataSource.SelectParameters("languageID" ).DefaultValue = langID
Me.ProvSqlDataSource.Select(DataSourceSelectArgume nts.Empty)

Also, try handling the querystring logic in your page_load event.

See the code below.

Hope this helps,
Jason Vermillion

<asp:SqlDataSource ID="ProvSqlDataSource" runat="server"
SelectCommand="SELECT DISTINCT [province] FROM [provinces] WHERE
([languageID] = @languageID ) ORDER BY [province]">
<SelectParameters>
<asp:Parameter Name="languageID" />
</SelectParameters>
</asp:SqlDataSource>

Then in your page_load...

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim altlang As String
Dim lang As String

Dim langID As Int32

lang = Request.QueryString("lang")
If Request.QueryString("lang") = "" Then
lang = "en"
End If

'Response.Write("<br />The Lang is--" & lang)
If (lang = "fr") Then
langID = 2
altlang = "fr"
Else ' lang = "en"
langID = 1
altlang = "en"
End If

Me.ProvSqlDataSource.SelectParameters("languageID" ).DefaultValue = langID
Me.ProvSqlDataSource.Select(DataSourceSelectArgume nts.Empty)
End Sub
"Brad Isaacs" wrote:
Good evening friends,

I have added a Drop Down List box control to my web form. I am using the
web.config connection string to access my SQL Server 2000 db. Inside that
db I have a table named Provinces.

The table contains 3 fields :

LanguageID
ProvinceID
Province

I have also added a SqlDataSource object and configured it to retrieve
Provinces based on my parameter named @languageID

<asp:DropDownList ID="ddlProvince" runat="server"
DataSourceID="ProvSqlDataSource"

DataTextField="province" DataValueField="province" Width="196px">

</asp:DropDownList></td>

<asp:SqlDataSource ID="ProvSqlDataSource" runat="server"
CacheExpirationPolicy="Sliding"

ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"

SelectCommand="SELECT DISTINCT [province] FROM [provinces] WHERE
([languageID] = @languageID ) ORDER BY [province]">

</asp:SqlDataSource>

My problem is how I may gain access to the @languageID parameter. I feel
kinda stoopid, as this may be an easy solution.

It has to change either "1" for English and "2" for French,,,

Depending on the language chosen for the web form page. So I use this code
to retrieve the language chosen by the user.

<%
Dim languageSuffix, altlang, lang As String

Dim langID As Int32

lang = Request.QueryString("lang")
If Request.QueryString("lang") = "" Then

lang = "en"

End If

'Response.Write("<br />The Lang is--" & lang)
If (lang = "fr") Then

langID = 2

altlang = "fr"

Else ' lang = "en"

langID = 1

altlang = "en"

End If
Response.Write(("<br />The LangID is--" & langID))
%>

But I cannot for the life of me figure out how to gain access to the
@languageID and add 1 if English or 2 if French.
Any ideas, code examples or urls would be greatly appreciated,

Thanks in advance

~Brad
Jan 30 '07 #2
Jason,

Thanks for your input.

I was able to use the QueryString parameter. My problem was that I was not
sending the langID=1 or langID=2 when the user had chosen a language for the
page. I needed to PASS the value. Once I passed the value, all I had to do
was add the QueryString parameter and it all worked.

Thanks again for your input.

~Brad
"Jason Vermillion" <Ja*************@discussions.microsoft.comwrote in
message news:3E**********************************@microsof t.com...
Brad,

You can manually update your parameters and select the data through code
via:

Me.ProvSqlDataSource.SelectParameters("languageID" ).DefaultValue = langID
Me.ProvSqlDataSource.Select(DataSourceSelectArgume nts.Empty)

Also, try handling the querystring logic in your page_load event.

See the code below.

Hope this helps,
Jason Vermillion

<asp:SqlDataSource ID="ProvSqlDataSource" runat="server"
SelectCommand="SELECT DISTINCT [province] FROM [provinces] WHERE
([languageID] = @languageID ) ORDER BY [province]">
<SelectParameters>
<asp:Parameter Name="languageID" />
</SelectParameters>
</asp:SqlDataSource>

Then in your page_load...

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Handles Me.Load
Dim altlang As String
Dim lang As String

Dim langID As Int32

lang = Request.QueryString("lang")
If Request.QueryString("lang") = "" Then
lang = "en"
End If

'Response.Write("<br />The Lang is--" & lang)
If (lang = "fr") Then
langID = 2
altlang = "fr"
Else ' lang = "en"
langID = 1
altlang = "en"
End If

Me.ProvSqlDataSource.SelectParameters("languageID" ).DefaultValue =
langID
Me.ProvSqlDataSource.Select(DataSourceSelectArgume nts.Empty)
End Sub
"Brad Isaacs" wrote:
>Good evening friends,

I have added a Drop Down List box control to my web form. I am using the
web.config connection string to access my SQL Server 2000 db. Inside
that
db I have a table named Provinces.

The table contains 3 fields :

LanguageID
ProvinceID
Province

I have also added a SqlDataSource object and configured it to retrieve
Provinces based on my parameter named @languageID

<asp:DropDownList ID="ddlProvince" runat="server"
DataSourceID="ProvSqlDataSource"

DataTextField="province" DataValueField="province" Width="196px">

</asp:DropDownList></td>

<asp:SqlDataSource ID="ProvSqlDataSource" runat="server"
CacheExpirationPolicy="Sliding"

ConnectionString="<%$ ConnectionStrings:MyConnectionString %>"

SelectCommand="SELECT DISTINCT [province] FROM [provinces] WHERE
([languageID] = @languageID ) ORDER BY [province]">

</asp:SqlDataSource>

My problem is how I may gain access to the @languageID parameter. I
feel
kinda stoopid, as this may be an easy solution.

It has to change either "1" for English and "2" for French,,,

Depending on the language chosen for the web form page. So I use this
code
to retrieve the language chosen by the user.

<%
Dim languageSuffix, altlang, lang As String

Dim langID As Int32

lang = Request.QueryString("lang")
If Request.QueryString("lang") = "" Then

lang = "en"

End If

'Response.Write("<br />The Lang is--" & lang)
If (lang = "fr") Then

langID = 2

altlang = "fr"

Else ' lang = "en"

langID = 1

altlang = "en"

End If
Response.Write(("<br />The LangID is--" & langID))
%>

But I cannot for the life of me figure out how to gain access to the
@languageID and add 1 if English or 2 if French.
Any ideas, code examples or urls would be greatly appreciated,

Thanks in advance

~Brad

Jan 31 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Swetha | last post by:
Hello I have a DropDownList that I am populating using the following SqlDataSource: <asp:DropDownList ID="parentIDDropDownList" runat="server" DataSourceID="SqlDataSource3"...
4
by: P. Yanzick | last post by:
Hello, I've been playing with master/detail views as well as editing in the gridview, and I ran across a strange problem that I am not exactly sure where to go to try to solve. I have 2...
6
by: Dabbler | last post by:
I have a dropdownlist in a GridView ItemTemplate. I need to bind the ddl to an SqlDataSource, then have a value from a boundfield in the row be passed as the keyfield for select where clause. Im...
3
by: K B | last post by:
Hi, I've tried this several ways but get the error that the control can't be found. I have a details view with a dropdownlist in the EditItemTemplate populated and assigned the selected value...
1
by: Jason Wilson | last post by:
I have two dropdownlists that are bound to the same datasource and I have a couple of questions: 1) Because they are bound to the same datasource, I am assuming that they only make 1 round trip...
0
by: andy | last post by:
Hi, I have a form uses several dropdownlists to narrow a set of criteria. ( This is in turn used to control what is shown on a gridview. ) With each, the user selects an entry and then the next...
3
by: gsauns | last post by:
Hello, I have an ASP.NET app with a DropDownList on the page, which is bound to values from a table. I have a Repeater control on the page whose displayed data is dependent on the DropDownList...
0
by: lamolap | last post by:
i have 1 gridview , a dropdownlist inside a gridview and a commandfield of (edit, update and cancel) my gidview looks like this Edit Surname Initials ...
1
by: Brett | last post by:
I have a DropDownList in an ASP.NET web form that is populated with items from a lookup table by binding that DropDownList to a SqlDataSource. However, the items in the lookup table can change over...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.