vb.net 二级联动 datatable生成json数据

前端之家收集整理的这篇文章主要介绍了vb.net 二级联动 datatable生成json数据前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
js部分
function GetAccNTData() {
    $("#drpNaturalCode").empty();


    var strId = $("#DrpAccountGroup").attr("value");

    if (strId != ""&& typeof(strId)!="undefined" )
  {

        $.get("../Handler/GetAccNTDataInfo.ashx",{ GroupId: escape(strId),date: new Date().getTime() },function (result) {


            $("#drpNaturalCode").append($("<option></option>").val("0").html("==请选择科目=="));

            var datas = eval(result);

            for (var j = 0; j < datas.length; j++) 
            {

                $("#drpNaturalCode").append($("<option></option>").val(datas[j].NaturalCode).html(datas[j].NaturalCode + "--" + datas[j].ACCNT_NAME));

            }

        })
    }
}




' 一般处理文件
    Dim groupName As String = HttpUtility.UrlDecode(context.Request.QueryString("GroupId").ToString())
                
                Dim connectionString As String = ConfigurationManager.ConnectionStrings("ConnectionString_EIS").ConnectionString
            
                Dim strsql As String = "SELECT NaturalCode,ACCNT_NAME FROM tbl_Account WHERE AccountGroup='" & groupName.Trim() & "'"
                
                ' Dim strsql As String = "SELECT NaturalCode,ACCNT_NAME FROM tbl_Account"
                Dim da As sqlDataAdapter = New sqlDataAdapter(strsql,connectionString)
            
                da.Fill(ds)
                
                Dim ti As TreeItem = New TreeItem()
              
                Dim jsonString As String = ti.CreateJsonParameters(ds.Tables(0))
                
                context.Response.Write(jsonString)
'方法 Public Function CreateJsonParameters(ByVal dt As DataTable) As String Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder() If dt IsNot Nothing Then sb.Append("[") For i = 0 To dt.Rows.Count - 1 sb.Append("{") For j = 0 To dt.Columns.Count - 1 If j < dt.Columns.Count - 1 Then sb.Append(Chr(34) & dt.Columns(j).ColumnName.ToString() & Chr(34) & ":" & Chr(34) & dt.Rows(i)(j).ToString() & Chr(34) & ",") ElseIf (j = dt.Columns.Count - 1) Then sb.Append(Chr(34) & dt.Columns(j).ColumnName.ToString() & Chr(34) & ":" & Chr(34) & dt.Rows(i)(j).ToString() & Chr(34)) End If Next j If i = dt.Rows.Count - 1 Then sb.Append("}") Else sb.Append("},") End If Next i End If sb.Append("]") Return sb.ToString() End Function
原文链接:https://www.f2er.com/vb/258959.html

猜你在找的VB相关文章