31
Mi método de extensión JSON
Filed Under (.Net) by admin on 31-07-2008
//extensiones [
Public Module Extensiones
<Runtime.CompilerServices.Extension()> _
Public Function ToJSON(ByVal datos As Agromutua.Entity.DatosBancarios) As String
Dim datosBancarios As String
Dim prov As New Persistencia.Provincia
Dim pk() As Object = New Object() {datos.IdProvincia}
datosBancarios = “{Id: ‘” & datos.Id & “‘ ,” _
& “Banco: ‘” & datos.Banco & “‘ ,” _
& “Calle: ‘” & datos.Calle & “‘ ,” _
& “Agencia: ‘” & datos.Agencia & “‘ ,” _
& “CodPostal: ‘” & datos.CodigoPostal & “‘ ,” _
& “CuentaBanco: ‘” & datos.CuentaBanco & “‘ ,” _
& “CuentaOficina: ‘” & datos.CuentaOficina & “‘ ,” _
& “CuentaDC: ‘” & datos.CuentaDC & “‘ ,” _
& “CuentaNumero: ‘” & datos.CuentaNumero & “‘ ,” _
& “Provincia: ‘” & datos.IdProvincia & “‘ ,” _
& “NProvincia: ‘” & prov.Obtener(pk).Nombre & “‘ ,” _
& “Municipio: ‘” & datos.Municipio & “‘}”
Return datosBancarios
End Function
End Module
//trabajando con JSON – Objetos JS
function cambiaDatosBancarios() {
var msg = document.getElementById(‘<%=cboImportar.ClientID %>’).value;
if (msg != “”)
{
var x = eval(“(“ + msg + “)”);
document.getElementById(‘<%=txtidDatosBAncarios.ClientID %>’).value = x.Id;
document.getElementById(‘<%=txtBanco.ClientID %>’).value = x.Banco;
document.getElementById(‘<%=txtBancoCalle.ClientID %>’).value = x.Calle;
document.getElementById(‘<%=txtAgenciaNo.ClientID %>’).value = x.Agencia;
document.getElementById(‘<%=txtBancoCP.ClientID %>’).value = x.CodPostal;
document.getElementById(‘<%=txtCuentaBanco.ClientID %>’).value = x.CuentaBanco;
document.getElementById(‘<%=txtCuentaOficina.ClientID %>’).value = x.CuentaOficina;
document.getElementById(‘<%=txtCuentaDC.ClientID %>’).value = x.CuentaDC;
document.getElementById(‘<%=txtCuentaNumero.ClientID %>’).value = x.CuentaNumero;
document.getElementById(‘<%=txtBancoMunicipio.ClientID %>’).value = x.Municipio;
document.getElementById(‘<%=txtBancoProvincia.ClientID %>’).value = x.Provincia;
document.getElementById(‘<%=lblBancoProvincia.ClientID %>’).innerHTML = x.NProvincia;
DatosBancarioOnBlur()
}
else limpiarDatosBancarios()
}