mercredi 3 septembre 2014

Gridview completly editable created at runtime in code behind


Vote count:

0




hi guys i already created a gridview dynamically but i need to put it completely editable from 3er column with textboxes no labels i have tryed in rowdatabound and i certainly can see the textboxes but the problem is how to pass the values from a datatable into these textboxes and no showing the data in this Web.UI.WebControls.Literal i just need the values in the textboxes controls


the data is in a datatable here a put the metod which bind this to columns created dinamically



foreach (DataColumn columna in Web_fechas.Columns)
{
if (columna.Ordinal == 0)
{
BoundField vaux_columnacedula = new BoundField();
vaux_columnacedula.HeaderText = "Empleado";
vaux_columnacedula.DataField = "Empleado";
vaux_columnacedula.ReadOnly = true;
vaux_columnacedula.HeaderStyle.Width = 40;
Grdatos.Columns.Add(vaux_columnacedula);


}
else if (columna.Ordinal == 1)
{
BoundField vaux_columnanombre = new BoundField();
vaux_columnanombre.HeaderText = "Nombre Empleado";
vaux_columnanombre.DataField = "Nombre";
vaux_columnanombre.ReadOnly = true;
vaux_columnanombre.HeaderStyle.Width = 120;
vaux_columnanombre.HeaderStyle.Wrap = false;
vaux_columnanombre.ItemStyle.Wrap = false;
vaux_columnanombre.ItemStyle.Width = 120;
Grdatos.Columns.Add(vaux_columnanombre);

// Grdatos1.Columns.Add(vaux_columnanombre);
}
else
{
TemplateField Vaux_templateFecha = new TemplateField();
Vaux_templateFecha.HeaderTemplate = new GridViewHeaderTemplate(columna.ColumnName.Trim());
Vaux_templateFecha.EditItemTemplate = new GridViewEditTemplate(columna.ColumnName.Trim());
Vaux_templateFecha.ItemTemplate = new GridViewItemTemplate(columna.ColumnName.Trim());

}


and now i put de rowdatabound event when a put the textboxes


protected void Grdatos_RowDataBound1(object sender, GridViewRowEventArgs e) {



if (DataControlRowType.DataRow == e.Row.RowType && e.Row.RowState == DataControlRowState.Normal)
{
TextBox tx = new TextBox(); //here i m adding a control.
tx.ID = "tx";
tx.Attributes.Add("runat", "server");
// int i = e.Row.Cells.Count;
// i = i - 1;
e.Row.Cells[2].Controls.Add(tx);
tx.Text = (e.Row.DataItem as DataRowView).Row[2].ToString(); //here i can pass the value to a textbox but i need only to see one control the textbox no the other control
}


the fact its that i see my information in two controls and i just need the textboxes i hope i explaint it clear please someone could help me with this i have spent several days lokking for a solution thanks



asked 46 secs ago







Gridview completly editable created at runtime in code behind

Aucun commentaire:

Enregistrer un commentaire