ASP.NET - buscar registro en grid?

 
Vista:
Imágen de perfil de diana

buscar registro en grid?

Publicado por diana (44 intervenciones) el 05/10/2005 20:57:57
Hola, tengo un problema al querer buscar un registro en un grid q llene con un dataset, al tiempo q ejecuto el codigo de buesuqda me manda q mi tabla no tiene una llave, como puedo establecerle una llave a un Datatable?? mi codigo es este:

//need to set the primary key or use strongly typed dataset

DataColumn[] keys = new DataColumn[1];
DataRow foundRow;

// Create an array for the key values to find.
object[]findTheseVals = new object[1];
// Set the values of the keys to find.
findTheseVals[0] = this.txtPalabras.Text ;
DataTable oTable;
DataSet ds= new DataSet();
ds=(DataSet) this.Session["dsCatalogo"];
keys[0] = ds.Tables[0].Columns["CLAVE"];
oTable=ds.Tables[0].Copy();
oTable.PrimaryKey=keys;
foundRow = oTable.Rows.Find(findTheseVals);
// Display column 1 of the found row.
if(foundRow != null)
{
this.lstResultados.Items.Add(foundRow[1].ToString());
lstResultados.Visible=true;
this.lblFlecha.Text=">>>";
this.lblFlecha.Visible=true;
}
else
{
lstResultados.Visible=false;
this.lblFlecha.Text=">>> No se encontraron resultados.";
this.lblFlecha.Visible=true;
}
foundRow.Delete();

de antemano muchas gracias por su ayuda!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de diana

RE:buscar registro en grid?

Publicado por diana (44 intervenciones) el 06/10/2005 02:40:47
me contesto a mi misma, ya q ya pude y pues por si alguien mas algun dia lo necesita no se traven tanto tiempo como yo, aqui va

private void btnBuscar_Click(object sender, System.EventArgs e)
{
DataSet ds= new DataSet();
ds=(DataSet) this.Session["dsCatalogo"];
DataView oView= new DataView(ds.Tables[0]);
oView.RowFilter="CLAVE like '%"+this.txtPalabras.Text+"%' or DATO1 like '%"+this.txtPalabras.Text+ "%' or DATO2 like '%"+this.txtPalabras.Text+"%'";
if(oView.Count > 0)
{
this.lstResultados.Items.Clear();

for (int icont = 0; icont<oView.Count;icont++)
this.lstResultados.Items.Add(oView[icont]["CLAVE"].ToString());
lstResultados.Visible=true;
this.lblFlecha.Text=">>>";
this.lblFlecha.Visible=true;
}
else
{
lstResultados.Visible=false;
this.lblFlecha.Text=">>> No se encontraron resultados.";
this.lblFlecha.Visible=true;
}
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar