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

duda sobre obtener valores en la fila de un gridview

Estas en el tema de duda sobre obtener valores en la fila de un gridview en el foro de .NET en Foros del Web. Miren tengo un gridview y quiero que al seleccionar una fila, se me carguen esos valores para despues pasarselos uno a uno a un formulario ...
  #1 (permalink)  
Antiguo 23/09/2008, 11:46
Avatar de marliesmartinez  
Fecha de Ingreso: marzo-2008
Mensajes: 38
Antigüedad: 16 años, 1 mes
Puntos: 0
Exclamación duda sobre obtener valores en la fila de un gridview

Miren tengo un gridview y quiero que al seleccionar una fila, se me carguen esos valores para despues pasarselos uno a uno a un formulario y asi poder realizar otras acciones.

Trate de obtener los valores asi

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int fila = GridView1.SelectedIndex;

for (int i=1, i<.......)
txtTitleInformation.Text = GridView1.Rows[fila].Cells[i].Text;
txt.....
txt.......
}

y asi llenar el formulario con los datos de la fila que se seleccione.

La propiedad text debe devolver el texto que esta en esa celda de esa fila.

Pero no me funciona, ya busque las mil maneras por favor alguien ha hecho algo parecido.

txtTitleInformation.text me da igual " ", vacio.
  #2 (permalink)  
Antiguo 24/09/2008, 06:45
 
Fecha de Ingreso: septiembre-2008
Mensajes: 2
Antigüedad: 15 años, 7 meses
Puntos: 0
Respuesta: duda sobre obtener valores en la fila de un gridview

Hola,

No sé si exactamente es lo que necesitas pero creo que podrías usar el "onrowcommand" del gridView eso te permite en el método recibir un argumento de tipo...

protected void OnRowCommand_ShowQuery(Object sender, GridViewCommandEventArgs e){

string valor=e.CommandArgument.toString();


}

Ahora en valor tienes la clave primaria de la fila del datagridview que has seleccionado y puedes consultar sus valores en tu base de datos.
  #3 (permalink)  
Antiguo 24/09/2008, 08:39
Avatar de marliesmartinez  
Fecha de Ingreso: marzo-2008
Mensajes: 38
Antigüedad: 16 años, 1 mes
Puntos: 0
Respuesta: duda sobre obtener valores en la fila de un gridview

Ya lo resolvi utilizando el dataKeyName, aqui va mi codigo donde tomo el valor de una fila seleccionada y se lo paso a un formulario.

protected void GVSelectUpdate_SelectedIndexChanged1(object sender, EventArgs e)
{
string informationId = GVSelectUpdate.SelectedDataKey["informationId"].ToString();
string imagesId = GVSelectUpdate.SelectedDataKey["imagesId"].ToString();

string SelectInformationUpdate = @"SELECT sectionId,informationTypeId,informationTitle,infor mationSumary,informationText,informationActive,ima gesId
FROM dbo.tbl_information WHERE (informationId = @informationId)";

DataView dvSelectInformationUpdate = BDataSql.SelectSqlDS(cxn,SelectInformationUpdate, new Parameter("informationId", TypeCode.String, informationId));


string SelectImageUpdate = @"SELECT imagesCaption,imagesFileName,images FROM tbl_images
WHERE (imagesId = @imagesId)";

DataView dvSelectImageUpdate = BDataSql.SelectSqlDS(cxn, SelectImageUpdate, new Parameter("imagesId", TypeCode.String, imagesId));


tbl_sectionTableAdapter tbl_ddlSection2= new tbl_sectionTableAdapter();
DataTable FillddlSection2 = tbl_ddlSection2.GetData();
Utility.FillDDL(ddlSection2, FillddlSection2, "sectionName", "sectionId", ddlSeccion.SelectedValue.ToString());

tbl_informationTypeTableAdapter tbl_ddlTypeInformation2 = new tbl_informationTypeTableAdapter();
DataTable FillddlTypeInformation2 = tbl_ddlTypeInformation2.GetData();
Utility.FillDDL(ddlTypeInformation2, FillddlTypeInformation2, "informationTypeDescription", "informationTypeId", ddlTypeInformation.SelectedValue.ToString());
txtTitle.Text = dvSelectInformationUpdate.Table.Rows[0]["informationTitle"].ToString();
txtSumary.Text = dvSelectInformationUpdate.Table.Rows[0]["informationSumary"].ToString();
txtInformation.Text = dvSelectInformationUpdate.Table.Rows[0]["informationText"].ToString();
chkBoxActive.Checked = bool.Parse(dvSelectInformationUpdate.Table.Rows[0]["informationActive"].ToString());
txtImageCaption.Text = dvSelectImageUpdate.Table.Rows[0]["imagesCaption"].ToString();

}
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 03:04.