sAjaxSource being ignored
sAjaxSource being ignored
Hello,
I'm try to fill my gridview with sAjaxSource but doesn't works!
Somebody can help me please? I'm starting with DATATABLES and JSON/AJAX or whatever :)
My HTML:
$("#GridView2").dataTable({
"bJQueryUI": true,
"sPaginationType": "full_numbers",
"bServerSide": true,
"sAjaxSource": "Evolucao.aspx/CarregaEvolucao2",
"fnServerData": function (sSource, aoData, fnCallback) {
$.ajax({
"type": "POST",
"dataType": 'json',
"contentType": "application/json; charset=utf-8",
"url": sSource,
"data": "{'sEcho': '" + aoData[0].value + "'}",
"success": function (msg) {
fnCallback(msg.d);
}
});
}
});
My .NET:
Public Shared Function CarregaEvolucao2() As String
Dim connectionString As String = "Data Source=localhost;Initial Catalog=INVESTIMENTO;Integrated Security=True"
Dim dt As DataTable = New DataTable()
dt.TableName = "Evolucao"
dt.Columns.Add("Data")
dt.Columns.Add("Acao", GetType(Double))
dt.Columns.Add("r_acoes", GetType(String))
dt.Columns.Add("FII", GetType(Double))
Using con As New SqlConnection(connectionString)
Using cmd As New SqlCommand("sp_getEvolucao")
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con
con.Open()
Using sdr As SqlDataReader = cmd.ExecuteReader()
While sdr.Read()
Dim dr1 As DataRow = dt.NewRow()
dr1("Data") = DateTime.Parse(CType(sdr("DATA"), Date)).ToString("dd/MM/yyyy")
dr1("Acao") = String.Format("{0:n}", sdr("VLACAO"))
dr1("r_acoes") = CDbl(sdr("racao")).ToString("P")
dr1("FII") = String.Format("{0:n}", sdr("VLFII"))
dt.Rows.Add(dr1)
End While
con.Close()
End Using
End Using
End Using
Dim ds As New DataSet
ds.Tables.Add(dt)
Dim jss As New JavaScriptSerializer
Dim jsonString As String = jss.Serialize(ds.GetXml())
Return jsonString
End Function
Thanks
Replies
My HTML:
My VB.NET: