2011-12-07 7 views
1

2番目のリストアイテムの値を取得してテキストボックスに割り当てるにはどうすればよいですか?例えば、2番目のリストアイテムは「プロファイルを編集する」、textbox1のテキストチェンジの後にtextbox2は自動的に " は、ここに私のコードですJqueryリストアイテムを取得

<script language ="javascript" type="text/javascript"> 
    $(document).ready(function() { 
     $("#TextBox1").bind('change', function (e) { 
      if ($("#TextBox1").val() != '') { 
       sendData(); 
      } 

     }); 


     function sendData() { 
      var loc = window.location.href; 
      loc = (loc.substr(loc.length - 1, 1) == "/") ? loc + "t1ViewDB.aspx" : loc; 
      $.ajax({ 
       type: "POST", 
       url: loc + "/GetModuleList", 
       contentType: "application/json; charset=utf-8", 
       dataType: "json", 
       success: function (msg) { 
        if (msg.d) { 

         //Get the second list item and assign value to textbox2 
         //??? 
         $("#TextBox2").val(''); 


        } 
       }, 
       error: function() { 
        alert("An unexpected error has occurred during processing."); 
       } 

      }); 
     } 
    }); 


</script> 

バックエンドのコード

protected void Page_Load(object sender, EventArgs e) 
{ 

} 


[WebMethod()] 
public static ArrayList GetModuleList() 
{ 
    ArrayList listArr = new ArrayList(); 
    listArr.Add(new ListItem("Dashboard")); 
    listArr.Add(new ListItem("Edit Profile")); 
    listArr.Add(new ListItem("Change Password")); 
    return listArr; 
} 

答えて

0
インデックスで

ジャスト参照:

$("#TextBox2").val(msg.d[1]['Value']); 

Arraylist and webmethod

+0

こんにちは、私はアディを試してみます。テキストボックス2は私に "[オブジェクトオブジェクト]"を表示します – user998405

+0

更新を参照..... –

+0

またupvoteしてください –

関連する問題