级联下拉列表中的绑定值问题 [英] Trouble binding value from a cascading drop down

查看:102
本文介绍了级联下拉列表中的绑定值问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个似乎起作用的级联下拉框-但是,当我尝试绑定显示的文本时,我以某种方式绑定了与显示的文本相关联的ID.

我不知道问题出在我的网络服务中还是我绑定数据的方式.如果有人有任何想法,我将不胜感激.

我的网络方法:

I have cascading drop down boxes that appear to be working - BUT when I try to bind the displayed text I somehow bind the ID associated with the displayed text.

I don''t know if the problem is in my webservice or in the way I bind the data. If anyone has any ideas I would really appreciate it.

My Web Method:

WebMethod(); _
Public Function GetProcedure(ByVal knownCategoryValues As String, ByVal category As String) As CascadingDropDownNameValue()
       Dim strConnection As String = ConfigurationManager.ConnectionStrings("WPSConnectionString").ConnectionString
       Dim sqlConn As SqlConnection = New SqlConnection(strConnection)
       Dim strProcQuery As String = "SELECT  [Procedure], ProcID from Proc_Procedure where SubCategoryID = @SubCategoryID"
       Dim cmdFetchProc As SqlCommand = New SqlCommand(strProcQuery, sqlConn)

       Dim dtrProc As SqlDataReader
       Dim kvProc As StringDictionary = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues)

       Dim SubCategoryId As Integer

       If Not kvProc.ContainsKey("SubCategory") Or Not Int32.TryParse(kvProc("SubCategory"), SubCategoryId) Then
           Return Nothing
       End If

       cmdFetchProc.Parameters.AddWithValue("@SubCategoryID", SubCategoryId)

       Dim myProc As New List(Of CascadingDropDownNameValue)

       sqlConn.Open()
       dtrProc = cmdFetchProc.ExecuteReader

       While dtrProc.Read()
           Dim strProcName As String = dtrProc("Procedure").ToString
           Dim strProcId As Integer = dtrProc("ProcID")

           myProc.Add(New CascadingDropDownNameValue(strProcName, strProcId))
       End While

       Return myProc.ToArray
   End Function




我的数据绑定:




My data binding:

<asp:DropDownList ID="ddlprocedure" runat="server"
     SelectedValue=''<%# bind("Procedure") %>'' DataTextField="Procedure" DataValueField="ProcID">
     </asp:DropDownList>
     <asp:CascadingDropDown ID="ddlprocedure_cdd" runat="server"
     TargetControlID="ddlprocedure"
     Category="Procedure"
     PromptText="Select Procedure"
     LoadingText="Please wait..."
     ServicePath="~/ProcedureService.asmx"
     ServiceMethod="GetProcedure"
     ParentcontrolID="ddlSubCategory">
     </asp:CascadingDropDown>

     </InsertItemTemplate>
     <ItemTemplate>
     <asp:Label ID="Label1" runat="server" Text=''<%# Bind("Procedure") %>''></asp:Label>

推荐答案

我找到了解决此问题的方法.

我绑定了级联下拉扩展器中的数据,而不是下拉控件本身.此数据显示为ID,后跟":::",后跟文本值(例如13 ::: sometext)

为了解决这个问题,我在下拉框中创建了一个onindexchange子对象,该子对象使用indexof和substring提取我想要的文本-然后将最终值设置为会话变量.

然后,我为我的detailsview修改了插入和更新参数字段,以使用会话参数代替受影响字段的常规参数.

没有人会称它为优雅,但它可以完成工作.

I figured out a work-around for my issue.

I bound the data from my cascading drop down extender instead of the drop down control itself. This data appeared as the ID followed by ":::" followed by the text value (ex. 13:::sometext)

To deal with that, I created an onindexchange sub on the drop down box that uses indexof and substring to pull out the text I want - and then sets the final value to a session variable.

Then I modified my insert and update parameter fields for my detailsview to use a session parameter instead of a regular parameter for the affected field.

Nobody is going to call it elegant, but it gets the job done.

   Private Sub proc_trim(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim ddlvar As CascadingDropDown = CType(DetailsView1.FindControl("ddlprocedure_cdd"), CascadingDropDown)
        Dim sbad As String = ddlvar.SelectedValue
        If sbad.IndexOf(":::") < 0 Then
            Session("clean_proc") = sbad
        Else
            Dim i As Integer = sbad.IndexOf(":::")
            Dim smid As String = sbad.Substring(i)
            Dim sneed As String = smid.Substring(3)
            Session("clean_proc") = sneed
        End If
    End Sub


.....

<asp:DropDownList ID="ddlprocedure" runat="server" OnSelectedIndexChanged="proc_trim" 
DataTextField="Procedure" DataValueField="Procedure">
</asp:DropDownList>
<asp:CascadingDropDown ID="ddlprocedure_cdd" runat="server" 
           TargetControlID="ddlprocedure"
           Category="Procedure"
           PromptText="Select Procedure"
           LoadingText="Please wait..."
           ServicePath="~/ProcedureService.asmx"
           ServiceMethod="GetProcedure"
           ParentcontrolID="ddlSubCategory">      
</asp:CascadingDropDown>

.....

<InsertParameters>
<asp:SessionParameter Name="procedure" SessionField="clean_proc" Type="String" />
</InsertParameters>


这篇关于级联下拉列表中的绑定值问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆