2013-02-16 66 views
2

我有一個用戶選擇產品的頁面。然後,我希望使用所選的ddl值填充文本框的值,以便在必要時更新值。我的ddl正在正確填充。如何將textbox.text分配給選定的下拉列表值?

當我調試這個時,文本框uxProductFamilyUpvalue似乎分配了ddlProductFamilies.SelectedValue,但當我返回到頁面時,文本框爲空。

任何想法? TY

Imports ThomasOE.Globals 
Imports ThomasOE.Utilities 
Imports ThomasOE.Product 
Imports System.Data 
Imports System.Web.UI.WebControls 

Public Class frmProducts 
    Inherits System.Web.UI.Page 

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load     
     If Not IsPostBack Then 
      FillProductTypesDropdown() 
      DisplayLoginDetails(Master, Session.Item(SSNLOGINNAME), Session.Item(SSNCURRENTDATETIME)) 
     End If 

    End Sub 

    Private Sub FillProductTypesDropdown() 
     Dim objProduct As New Product 

     Try 

      objProduct.FillProductTypeDS() 

      ddlProductTypes.Items.Clear() 
      ddlProductTypes.Items.Add(String.Empty) 

      For i As Integer = 0 To objProduct.ProductTypeDS.Tables(0).Rows.Count - 1 
       ddlProductTypes.Items.Add(objProduct.ProductTypeDS.Tables(0).Rows(i).Item("product_type")) 
      Next 

      objProduct = Nothing 

     Catch ex As Exception 

     End Try 

    End Sub 

    Private Sub FillProductFamiliesDropdown() 

     Dim objProduct As New Product 

     Try 

      objProduct.FillProductFamilyDS(ddlProductTypes.Text) 

      ddlProductFamilies.Items.Clear() 
      ddlProductFamilies.Items.Add(String.Empty) 

      For i As Integer = 0 To objProduct.ProductFamilyDS.Tables(0).Rows.Count - 1 
       ddlProductFamilies.Items.Add(objProduct.ProductFamilyDS.Tables(0).Rows(i).Item("product_family"))    
      Next 

      objProduct = Nothing 

     Catch ex As Exception 

     End Try 


    End Sub 

    Protected Sub ddlProductTypes_SelectedIndexChanged1(sender As Object, e As EventArgs) Handles ddlProductTypes.SelectedIndexChanged 
     FillProductFamiliesDropdown() 

    End Sub 

    Private Sub UpdateProductPage()   
     uxProductTypeUp.Text = ddlProductTypes.SelectedValue 
     uxProductFamilyUp.Text = ddlProductFamilies.SelectedItem.Text 

    End Sub 

    Protected Sub ddlProductFamilies_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlProductFamilies.SelectedIndexChanged 
     'UpdateProductPage()    
     uxProductFamilyUp.Text = ddlProductFamilies.SelectedItem.Text 

    End Sub 
End Class 
+0

當您返回頁面時,下拉列表是否也爲空? – AbZy 2013-02-16 20:17:00

+0

編號。它有適當的選定項目。我能夠爲page_load上的文本框分配靜態值...但是 – Charlie 2013-02-16 21:07:42

回答

0

問題是由於您已經加載了頁面。 在改變DDL值的方式中,你可以使用AJAX調用jQuery。

包括jQuery的在網站母頭部

<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script> 

在這裏你有你的DDL添加類似

//DropDownList1 on change AJAX 
    $("#<%=DropdownList1.ClientID %>").change(function() { 
     GetData(); 
    }); 

    function GetData() { 
     $.ajax({ 
      type: "POST", 
      //here you have to call vb.net function 
      url: "Default.aspx/GetDataVB", 
      data: '{ddl_val: "' + $("#<%=DropDownList1.ClientID%>")[0].value + '" }', 
      contentType: "application/json; charset=utf-8", 
      dataType: "json", 
      success: GetData_OnSuccess, 
      failure: function (response) { 
       alert(response.d); 
      } 
    }); 
    } 
    function GetData_OnSuccess(response) { 
     $("#<%=TextBox1.ClientID%>").html(response.d); 
    } 

到VB代碼

<System.Web.Services.WebMethod()> _ 
Public Shared Function GetDataVB(ByVal ddl_val As String) As String 

    return ddl_val 

end function 
0

您可以將一個aspx頁面OnItemSelected事件到dropdownlist並在事件定義中設置TextBox的文本n後面的代碼

相關問題