Foros del Web » Programando para Internet » ASPX (.net) »

Problema al validar gridview

Estas en el tema de Problema al validar gridview en el foro de ASPX (.net) en Foros del Web. Tengo el siguiente código para validar un gridview componente del devexpress: protected void gvCatEmpresa_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e) { // Checks for null values. foreach (GridViewColumn ...
  #1 (permalink)  
Antiguo 05/07/2010, 18:01
 
Fecha de Ingreso: abril-2010
Mensajes: 3
Antigüedad: 14 años
Puntos: 0
Exclamación Problema al validar gridview

Tengo el siguiente código para validar un gridview componente del devexpress:

protected void gvCatEmpresa_RowValidating(object sender, DevExpress.Web.Data.ASPxDataValidationEventArgs e)
{
// Checks for null values.
foreach (GridViewColumn column in gvCatEmpresa.Columns)
{
GridViewDataColumn dataColumn = column as GridViewDataColumn;
if (dataColumn == null) continue;
if (e.NewValues[dataColumn.FieldName] == null)
e.Errors[dataColumn] = "El valor no puede ser Nulo.";
}
// Displays the error row if there is at least one error.
if (e.Errors.Count > 0) e.RowError = "Favor de llenar todos los campos.";

if (e.NewValues["razonSocial"] != null &&
e.NewValues["razonSocial"].ToString().Length < 2)
{
AddError(e.Errors, gvCatEmpresa.Columns["razonSocial"],
"Razon Social debe de contener al menos dos caracteres de longitud.");
}
if (string.IsNullOrEmpty(e.RowError) && e.Errors.Count > 0)
e.RowError = "Favor de corregir todos los errores.";
}
void AddError(Dictionary<GridViewColumn, string> errors,GridViewColumn column, string errorText)
{
if (errors.ContainsKey(column)) return;
errors[column] = errorText;
}
protected void gvCatEmpresa_HtmlRowPrepared(object sender, ASPxGridViewTableRowEventArgs e)
{
// Checks whether the generated row has the errors.
bool hasError = e.GetValue("razonSocial").ToString().Length <= 1;
hasError = hasError || e.GetValue("razonSocial").ToString().Length <= 1;
// hasError = hasError || e.GetValue("Country") == null;
// If the row has the error(s), its text color is set to red.
if (hasError)
e.Row.ForeColor = System.Drawing.Color.Red;
}
protected void gvCatEmpresa_StartRowEditing(object sender, DevExpress.Web.Data.ASPxStartRowEditingEventArgs e)
{
// Validates the edited row if it isn't a new row,.
if (!gvCatEmpresa.IsNewRowEditing)
gvCatEmpresa.DoRowValidation();
}
protected void gvCatEmpresa_ParseValue(object sender, DevExpress.Web.Data.ASPxParseValueEventArgs e)
{
if (e.FieldName.Equals("numExterno"))
{
int numExt = 0;
if (e.Value != null)
if (!int.TryParse(e.Value.ToString(), out numExt))
throw new Exception("El Campo Num. Ext. debe ser entero");
}
if (e.FieldName.Equals("numInterno"))
{
int numInt = 0;
if (e.Value != null)
if (!int.TryParse(e.Value.ToString(), out numInt))
throw new Exception("El Campo Num. Int. debe ser entero");
}
if (e.FieldName.Equals("codigoPostal"))
{
int cp = 0;
if (e.Value != null)
if (!int.TryParse(e.Value.ToString(), out cp))
throw new Exception("El Campo CP. debe ser entero");
}
}

Con ésto me manda el error: Referencia a Objeto no establecida como instancia de un objeto en la parte del htmlrowprepared, cuando en otra pagina en que la tabla tiene solo 2 columnas si me funciona ese codigo

Ademas cuando quito parte del codigo y ya no me sale ese error me sale el error pero en el codigo c# y no en la pagina

Ayudenmeeeeee!

Etiquetas: asp, devexpress, gridview
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 01:21.