2017-05-30 23 views
0

ご覧のとおり、選択ボックスがあります。私はaspネット経由でms SQLデータベースからデータを引き出すが、私はそれを行う方法がわからない。設計コードは以下の通りです。Asp.netとSql Server Jqueryの自動データバインディング

jQueryのスクリプトコードで
<div class="form-group"> 
<label class="form-label">Basics</label> 
<div class="input-group"> 
<span class="input-group-addon"> 
<i class="fa fa-globe"></i> 
</span> 
<input type="text" class="form-control" placeholder="Type for Suggestions" id="typeahead-1"> 
</div> 
</div> 

var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California', 
'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii', 
'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana', 
'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota', 
'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire', 
'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota', 
'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island', 
'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont', 
'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming' 
]; 
$('#typeahead-1').typeahead({ 
hint: true, 
highlight: true, 
minLength: 1 
}, { 
name: 'states', 
displayKey: 'value', 
source: substringMatcher(states) 
}); 

İmage for design

答えて

0

あなたはデータ型はJSONではありません。このリンク

http://www.encodedna.com/jquery/twitter-bootstrap-typeahead-ajax-example-with-webapi.htm

$('#typeahead-1').typeahead({ 
    source: function (request, response) { 
     $.ajax({ 
      url: "/Home/Country/" + request, 
      dataType: "json", 
      type: "GET", 
      contentType: "application/json; charset=utf-8", 
      success: function (data) { 
       var arrCountry = []; 
       response($.map(data, function (item) { 
        arrCountry.push(item.CountryName); 
       })) 
       response(arrCountry);      
      }, 
      error: function (XMLHttpRequest, textStatus, errorThrown) { 
       alert(textStatus); 
      } 
     }); 
    }, 
    hint: true,    
    highlight: true,  
    minLength: 1    
}); 
+0

を参照することができます。私は通常のDataReaderでデータを取得しています。 –

+0

これはAsp.Netコード –

+0

でdataReaderデータをjson形式に変換することができます。または、データをリストまたは配列に変換できます。 –

関連する問題