Foros del Web » Programación para mayores de 30 ;) » .NET »

Problema con asp .net - datagrid

Estas en el tema de Problema con asp .net - datagrid en el foro de .NET en Foros del Web. Hola a todos, tengo un problema con un datagrid en asp .net. Lo cargo atraves de un xml, entonces tengo una de las columnas como ...
  #1 (permalink)  
Antiguo 11/09/2006, 04:25
 
Fecha de Ingreso: septiembre-2006
Mensajes: 1
Antigüedad: 17 años, 8 meses
Puntos: 0
Problema con asp .net - datagrid

Hola a todos, tengo un problema con un datagrid en asp .net.
Lo cargo atraves de un xml, entonces tengo una de las columnas como edit, con otra columna que cuando se pincha en edit, aparace un textbox, entonces el problema que se me plantea, es que, cuando doy a actualizar, no me hace nada, porque no se como se programa la parte de updatecommand.
De todos modo os adjunto el codigo para que lo podais ver.
Por favor es urgente, llevo una semana tras esto y no soy capaz de poder actualizar un dato que este en el datagrid, si alguien es tan amable de echar una mano, genial.
Mi pregunta en resumen es?, como se programa la parte de updatecommand de un datagrid de asp.net?

CODIGO:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace listado
{
/// <summary>
/// Descripción breve de WebForm1.
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid xml;
public System.Data.DataSet DsVersiones=new DataSet("ListadoVersiones");
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.TextBox nuevo_nombre;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.Button Button1;
public string path;
protected System.Web.UI.WebControls.TextBox nueva_version;
protected System.Web.UI.WebControls.Label error;
static System.Data.DataRow fila;
DataView CartView=new DataView();
DataTable Cart = new DataTable();


private void Page_Load(object sender, System.EventArgs e)
{
this.Load_Xml();
}

#region Código generado por el Diseñador de Web Forms
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: llamada requerida por el Diseñador de Web Forms ASP.NET.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Método necesario para admitir el Diseñador. No se puede modificar
/// el contenido del método con el editor de código.
/// </summary>
private void InitializeComponent()
{
this.xml.CancelCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.xml_CancelCommand);
this.xml.EditCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.xml_EditCommand);
this.xml.UpdateCommand += new System.Web.UI.WebControls.DataGridCommandEventHand ler(this.xml_UpdateCommand);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

public void xml_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.xml.EditItemIndex=e.Item.ItemIndex;
this.xml.DataBind();
}
public void Load_Xml()
{
string fichero = "Fich_Versiones\\Versiones.xml";
path = Server.MapPath(fichero);
this.DsVersiones.ReadXml(path,System.Data.XmlReadM ode.Auto);
this.DsVersiones.Tables["Fichero"].Columns[0].ReadOnly=true;
this.DsVersiones.Tables["Fichero"].Columns[2].ReadOnly=true;
this.xml.DataSource=this.DsVersiones.Tables["Fichero"];
this.xml.DataBind();
}
private void Button1_Click(object sender, System.EventArgs e)
{
if(this.nuevo_nombre.Text=="" || this.nueva_version.Text=="")
{
this.error.Text="LOS CAMPOS NO PUEDEN ESTAR VACIOS";
}
else
{
fila=this.DsVersiones.Tables["Fichero"].NewRow();
fila["Nombre"]=this.nuevo_nombre.Text;
fila["Version"]=this.nueva_version.Text;
fila["Fichero_Text"]="Archivos/" + this.nuevo_nombre.Text;
this.DsVersiones.Tables["Fichero"].Rows.Add(fila);
this.DsVersiones.WriteXml(path,System.Data.XmlWrit eMode.IgnoreSchema);
Response.Redirect("WebForm1.aspx");
}
}
private void xml_CancelCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
this.xml.EditItemIndex=-1;
this.xml.DataBind();
}
private void xml_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string valor= ((TextBox)e.Item.Cells[2].Controls[0]).Text;
fila=this.DsVersiones.Tables["Fichero"].NewRow();
fila["Version"]=valor;
this.DsVersiones.Tables["Fichero"].Rows.Add(fila);
this.DsVersiones.WriteXml(path,System.Data.XmlWrit eMode.IgnoreSchema);
Response.Redirect("WebForm1.aspx");
}
}
}
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:30.