开发者

CascadingDropDown taking two parameters

I have a page with 3 dropdownlist, 2nd and 3rd dropdownlist are added with CascadingDropDown. 3rd dropdownlist will take parameters from 1st and 2nd dropdownlist. So, in current example for CascadingDropDown i have found from google, they are only passing one parameter to the WebService method. How can pass two parameters to the service method, so that my 3rd dropdownlist will based on the SelectedValue of 1st and 2nd dropdownlist?

<WebMethod()> _
Public Function GetTeams(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
    Dim strConnection As String = ConfigurationManager.ConnectionStrings("nerdlinessConnection").ConnectionString
    Dim sqlConn As SqlConnection = New SqlConnection(strConnection)
    Dim strTeamQuery As String = "SELECT * FROM TEAM WHERE conf_id = @confid"
    Dim cmdFetchTeam As SqlCommand = New SqlCommand(strTeamQuery, sqlConn)

    Dim dtrTeam As SqlDataReader
    Dim kvTeam As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)

    Dim intConfId As Integer

    If Not kvTeam.ContainsKey("Confe开发者_运维百科rence") Or Not Int32.TryParse(kvTeam("Conference"), intConfId) Then
        Return Nothing
    End If

    cmdFetchTeam.Parameters.AddWithValue("@confid", intConfId)
    Dim myTeams As New List(Of CascadingDropDownNameValue)

    sqlConn.Open()
    dtrTeam = cmdFetchTeam.ExecuteReader

    While dtrTeam.Read()
        Dim strTeamName As String = dtrTeam("team_name").ToString
        Dim strTeamId As String = dtrTeam("team_id").ToString

        myTeams.Add(New CascadingDropDownNameValue(strTeamName, strTeamId))
    End While

    Return myTeams.ToArray
End Function

This is the sample code i found! As you can see in the code, '@confid' will be passed from 2nd dropdownlist! So, hw do i modify this code to get the selected value from 1st dropdownlist as well??


Which web service are you referring to? Is it something you have written or someone else's webservice?

In case it is your webservice, update the method definition in it and pass two parameters. In case it is somone else's, contact the concerned person to know what best can be done.


It appears the poster is not asking about Web Services really, but about SqlCommand and adding parameters.

First, you should never EVER run sql straight from your web application like that. Put it in a stored procedure.

Second, you should run checks on the values coming in, because this is a good way for your web site users to use SQL injection attacks.

Now... Here is what you were looking for:

Dim strTeamQuery As String = "SELECT * FROM TEAM WHERE conf_id = @confid"

becomes

Dim strTeamQuery As String = "SELECT * FROM TEAM WHERE conf_id = @confid AND second_id = @secondId"

Then just add another one of these:

cmdFetchTeam.Parameters.AddWithValue("@confid", intConfId)

(with the other value, of course, like this)

cmdFetchTeam.Parameters.AddWithValue("@confid", intConfId)
cmdFetchTeam.Parameters.AddWithValue("@secondId", intSecondId)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜