English 中文(简体)
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("Conference") 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)




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签