PDA

View Full Version : ExtJs + Aspx + Json



abelq
25 Feb 2011, 6:17 AM
Hi!

I'm trying to fill a combo through jsonstore object, but I could not do it.

I work with Visual Web Developer 2008, ExtJs 3.3.1 and Newtonsoft.Json.Net35
This is the javacript code

//function Fill the JsonStore
function getDependencias() {
var store = new Ext.data.JsonStore({
url: 'Default.aspx/ListDependencias',
baseParams: { asUsuario: Ext.getCmp('txtUsuario').getValue() },
root: "data",
fields: [
{ name: 'codigo', type: 'int' },
{ name: 'descripcion', type: 'string' }
]
});
store.load();
return store;
}

//The Form
var simple = new Ext.FormPanel({
labelWidth: 75, // label settings here cascade unless overridden
url: 'Default.aspx',
frame: true,
title: 'Simple Form',
bodyStyle: 'padding:5px 5px 0',
width: 350,
defaults: { width: 230 },
defaultType: 'textfield',

items: [new Ext.form.TextField({
fieldLabel: 'Usuario',
id: 'txtUsuario',
name: 'txtUsuario',
listeners: {
'blur': function() {
var cmbDep = Ext.getCmp('cmbDependencia');
cmbDep.store = getDependencias();
}
}
}), new Ext.form.TextField({
fieldLabel: 'Contraseņa',
name: 'txtPass'
}), new Ext.form.ComboBox({
fieldLabel: 'Dependencia',
name: 'cmbDependencia',
id: 'cmbDependencia',
forceSelection: true,
store: getDependencias(), //asignandole el store
emptyText: 'Seleccione una Dependencia...',
//triggerAction: 'all',
editable: false
//displayField: 'dependencia',
//valueField: 'dependencia'
})
],
buttons: [{
text: 'Ingresar'}]
});

simple.render(document.body);

});



And this is the ASP.Net code

public string ListDependencias(string asUsuario )
{
DataTable lo_Datatable;
lo_Datatable = new DataTable();

//lblErrorPass.Text = "";
//lblErrorUsuario.Text = "";

//string cstr = Documentos.Properties.Settings.Default.connstring;

OracleConnection conn = new OracleConnection(cstr);
OracleCommand cmd = new OracleCommand();


string SQL = "select d.codigo,d.dependencia from doc_responsables r, doc_responsable_dependencia d where r.codigo = d.responsable and d.por_defecto = 1 and r.login = '" + asUsuario + "'";

cmd.Connection = conn;
cmd.CommandText = SQL;
cmd.CommandType = CommandType.Text;

conn.Open();

OracleDataAdapter adp = new OracleDataAdapter(cmd);
OracleDataReader dr = cmd.ExecuteReader();

adp.Fill(lo_Datatable);

adp.Dispose();

string json = JsonConvert.SerializeObject(lo_Datatable, Formatting.Indented);
return json;
}

Thank you

Abel

tryanDLS
25 Feb 2011, 7:23 AM
http://sencha.com/learn/Ext_Forum_Help#How_to_post_code_properly

You dumped a bunch of code, but don't say much about what's really wrong. Have you verified that a request is being made? Is it coming back? What does the returned JSON look like? I don't see a load or exception handler for your store - you should add these and set breakpoints to see what's happening. Use Firebug.