public TablaPrueba Respuesta() { TablaPrueba lalista = new TablaPrueba(); //var lalista = HttpContext.Current.Application["someList"] as TablaPrueba; //laetiqueta.Text = lalista.codigo.ToString(); return(lalista); }
public List <TablaPrueba> ObtenerDatos() { using (var Conn = new SqlConnection(CadenaConexion)) { //SqlConnection Conn = new SqlConnection(CadenaConexion); Conn.Open(); using (var Cmd = new SqlCommand("TraerDatos", Conn)) { Cmd.CommandType = CommandType.StoredProcedure; //Cmd.Parameters.AddWithValue("@Operacion", "X"); //Cmd.Parameters.AddWithValue("@id", 2); using (var dr = Cmd.ExecuteReader()) { if (dr.HasRows) { using (var dt = new DataTable()) { dt.Load(dr); List <TablaPrueba> studentList = new List <TablaPrueba>(); for (int i = 0; i < dt.Rows.Count; i++) { TablaPrueba student = new TablaPrueba(); student.beneficio = dt.Rows[i]["beneficio"].ToString(); student.importe = Convert.ToDouble(dt.Rows[i]["importe"]); student.fecha = Convert.ToDateTime(dt.Rows[i]["fecha"]); student.codigo = Convert.ToInt16(dt.Rows[i]["codigo"]); studentList.Add(student); } //StringBuilder sb = new StringBuilder(); //sb.Append("<table cellpadding='3' cellspacing='3' style='border: 1px solid #800000;font-size: 12pt;font-family:Arial'>"); //Add Table Header //sb.Append("<tr>"); //foreach (DataColumn column in dt.Columns) //{ // sb.Append("<th style='background-color: #3366ff;border: 1px solid #000'>" + column.ColumnName + "</th>"); //} //sb.Append("</tr>"); //Add Table Rows //foreach (DataRow row in dt.Rows) //{ // if (row.ItemArray[0].ToString() == "3") // { // string a = ""; // } // sb.Append("<tr>"); // //Add Table Columns // foreach (DataColumn column in dt.Columns) // { // sb.Append("<td style='width:100px;border: 1px solid #ccc'>" + row[column.ColumnName].ToString() + "</td>"); // } // sb.Append("</tr>"); //} //sb.Append("</table>"); //DynamicTable.Text = sb.ToString(); return(studentList); } } else { throw new Exception("Error: "); } } } } }
private void BindGrid() { string CadenaConexion = ConfigurationManager.ConnectionStrings["myConexion"].ConnectionString; using (var Conn = new SqlConnection(CadenaConexion)) { //SqlConnection Conn = new SqlConnection(CadenaConexion); Conn.Open(); using (var Cmd2 = new SqlCommand("select * from TablaPrueba1", Conn)) { //Cmd2.CommandType = CommandType.StoredProcedure; //Cmd.Parameters.AddWithValue("@Operacion", "X"); //Cmd.Parameters.AddWithValue("@id", 2); using (var dr2 = Cmd2.ExecuteReader()) { if (dr2.HasRows) { using (var dt2 = new DataTable()) { dt2.Load(dr2); List <TablaPrueba1> studentList1 = new List <TablaPrueba1>(); for (int a = 0; a < dt2.Rows.Count; a++) { TablaPrueba1 student1 = new TablaPrueba1(); student1.id = Convert.ToInt16(dt2.Rows[a]["id"]); student1.descri = dt2.Rows[a]["descri"].ToString(); studentList1.Add(student1); using (var Cmd = new SqlCommand("TraerDatos", Conn)) { Cmd.CommandType = CommandType.StoredProcedure; //Cmd.Parameters.AddWithValue("@Operacion", "X"); //Cmd.Parameters.AddWithValue("@id", 2); using (var dr = Cmd.ExecuteReader()) { if (dr.HasRows) { using (var dt = new DataTable()) { dt.Load(dr); List <TablaPrueba> studentList = new List <TablaPrueba>(); for (int i = 0; i < dt.Rows.Count; i++) { TablaPrueba student = new TablaPrueba(); student.id = i; student.beneficio = dt.Rows[i]["beneficio"].ToString(); if (Convert.ToInt16(dt.Rows[i]["codigo"]) == 15) { student.importe2 = Convert.ToDouble(dt.Rows[i]["importe"]); } else { student.importe = Convert.ToDouble(dt.Rows[i]["importe"]); } //student.importe = Convert.ToDouble(dt.Rows[i]["importe"]); student.fecha = Convert.ToDateTime(dt.Rows[i]["fecha"]); student.codigo = Convert.ToInt16(dt.Rows[i]["codigo"]); if (i == 2) { if (studentList1.Count > 0) { for (int x = 1; x == studentList1.Count; x++) { // student.detalle[i].id = studentList1[x].id; // student.detalle[i].descri = studentList1[x].descri; } } } studentList.Add(student); } gv_Beneficios.DataSource = studentList; gv_Beneficios.DataBind(); //GridView1.DataSource = studentList; //GridView1.DataBind(); Session["Datos"] = studentList; } } } } } } } } } } }