使用asp.net c #ddslick下拉json数据

时间:2013-11-20 14:05:34

标签: c# asp.net json jquery

我在网站上搜索但找不到我想要的内容。然后我最后问了一个问题。我的问题是我无法使用来自asp.net c#webmethod的json数据填充ddslick下拉列表。下拉列表显示默认值。但是当我点击下拉列表以查看其他选项时,没有任何反应。我可以'我认为,将数据填入下拉列表。 这是我的代码。有人能告诉我我做错了什么吗? Combo is not opening

public class ComboBox
{
     private bool _selected = false;
     public ComboBox()
     {
     }
     public string text { get; set; }
     public string value { get; set; }
     public bool selected
     {
          get { return _selected; }
          set { _selected = value; }
     }
     public string description{ get; set; }
}

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string GetVehicleComboData()
{
  SqlToolkit mySqlKit = new SqlToolkit();
  mySqlKit.DoConnect();
  DataTable dt = mySqlKit.DoDTstr("Select VehicleTypeId, VehicleTypeName, VehicleTypeInfo from TBLVEHICLETYPES UNION ALL select '0','Lütfen Araç Tipi Seçiniz','' Order by VehicleTypeId ");
  List<ComboBox> comboData = new List<ComboBox>();
  foreach (DataRow dr in dt.Rows)
  { 
    ComboBox combo = new ComboBox();
    combo.text = dr["VehicleTypeName"].ToString();
    combo.value = dr["VehicleTypeId"].ToString();
    combo.description = dr["VehicleTypeInfo"].ToString();
    comboData.Add(combo);
  }
  var jsonForVehicles = JsonConvert.SerializeObject(comboData, Formatting.Indented);
  mySqlKit.DoDisconnect();
  return jsonForVehicles;
}

Javascript代码

<script type="text/javascript">
$.ajax({   
    type: 'POST',
    url: 'CreateOffer.aspx/GetVehicleComboData',
    data: '{}',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (myData) {
        $('#demoTruncated').ddslick({
                data : myData,
                selectText: "Select a vehicle type",
                truncateDescription: true,
                onSelected: function (data) {
                    //callback function: do something with selectedData;
                    alert(data.selectedIndex);
                    displaySelectedData("5: Dropdown with truncated description", data);
                }
            });
    },
    error: function () {
    }
});
</script>

我用firebug调试javascript,我看到来自服务器端的myData对象如下所示。我只能看到一个物体。但我认为必须有4个物体。因为我在下拉列表中有4条记录。

myData:     对象{d =“[\ r \ n {\ r \ n”文字“:”Lü... ription“:”de4“\ r \ n} \ r \ n]”}

d:     “[{”text“:”LütfenAraçTipiSeçiniz“,”value“:”0“,”selected“:false,”description“:”“},{”text“:”TenteliTır“,”value“: “1”,“已选择”:false,“description”:“de1”},{“text”:“KapalıKasaTır”,“value”:“2”,“selected”:false,“description”:“de2 “},{”text“:”KamyonRömorkTır“,”value“:”3“,”selected“:false,”description“:”de3“},{”text“:”Kamyon“,”value“: “4”,“已选择”:false,“description”:“de4”}]“

0 个答案:

没有答案