DropDownList| SqlDataSource | and Parameters??~

Discussion in 'ASP .Net' started by Brad Isaacs, Jan 29, 2007.

  1. Brad Isaacs

    Brad Isaacs Guest

    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
     
    Brad Isaacs, Jan 29, 2007
    #1
    1. Advertising

  2. Brad,

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

    Me.ProvSqlDataSource.SelectParameters("languageID").DefaultValue = langID
    Me.ProvSqlDataSource.Select(DataSourceSelectArguments.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(DataSourceSelectArguments.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
    >
    >
    >
     
    =?Utf-8?B?SmFzb24gVmVybWlsbGlvbg==?=, Jan 30, 2007
    #2
    1. Advertising

  3. Brad Isaacs

    Brad Isaacs Guest

    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" <> wrote in
    message news:...
    > Brad,
    >
    > You can manually update your parameters and select the data through code
    > via:
    >
    > Me.ProvSqlDataSource.SelectParameters("languageID").DefaultValue = langID
    > Me.ProvSqlDataSource.Select(DataSourceSelectArguments.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(DataSourceSelectArguments.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
    >>
    >>
    >>
     
    Brad Isaacs, Jan 31, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGFuaWVsIFIuIEgu?=

    Problems with Parameters and SQLDataSource

    =?Utf-8?B?RGFuaWVsIFIuIEgu?=, Jul 19, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    9,659
    roadhawk
    Dec 31, 2009
  2. =?Utf-8?B?Q0JLb3dpdHo=?=

    SQLDataSource and Blank Parameters

    =?Utf-8?B?Q0JLb3dpdHo=?=, Mar 7, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    321
    =?Utf-8?B?Q0JLb3dpdHo=?=
    Mar 7, 2007
  3. Guest
    Replies:
    2
    Views:
    1,955
    Guest
    Aug 18, 2007
  4. tyea
    Replies:
    1
    Views:
    1,351
  5. Scott.Metzger
    Replies:
    4
    Views:
    1,059
    Alexey Smirnov
    Oct 6, 2009
Loading...

Share This Page