Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > how to bring textbox in gridview load
 

how to bring textbox in gridview load

hi alll

i want to show the values in the gridview in the textbox
i dnt want to move over to click "edit" and then the row changing into textbox
is it possible to produce all the values in the grid in the textbox itself at the load event of the grid view
if it s possbile then please do give me the code
as how to do

tnx n advance
knortix  Saturday, July 22, 2006 6:06 AM

Use a template field.

<asp:gridview id="gvFoo" runat="server" autogeneratecolumns="false">
<columns>
<asp:templatefield>
<itemtemplate>
<asp:textbox id="tbFoo" runat="server" text='<%# DataBinder.Eval(Container.DataItem, "foo") %>' />
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>

If you need to manually set the data, remove the text='<%# ... %>' part. Setup the event handler for the RowDataBound event to set the text of the textbox for each row.

protected void gvFoo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
TextBox tb = (TextBox)e.Row.FindControl("tbFoo");
tb.Text = "foobar";
}
}

jshepler  Sunday, July 23, 2006 2:58 PM

Use a template field.

<asp:gridview id="gvFoo" runat="server" autogeneratecolumns="false">
<columns>
<asp:templatefield>
<itemtemplate>
<asp:textbox id="tbFoo" runat="server" text='<%# DataBinder.Eval(Container.DataItem, "foo") %>' />
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>

If you need to manually set the data, remove the text='<%# ... %>' part. Setup the event handler for the RowDataBound event to set the text of the textbox for each row.

protected void gvFoo_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
TextBox tb = (TextBox)e.Row.FindControl("tbFoo");
tb.Text = "foobar";
}
}

jshepler  Sunday, July 23, 2006 2:58 PM

hey...

i did as wat u said

<asp:gridview id="gvFoo" runat="server" autogeneratecolumns="false">
<columns>
<asp:templatefield>
<itemtemplate>
<asp:textbox id="tbFoo" runat="server" text='<%# DataBinder.Eval(Container.DataItem, "foo") %>' />
</itemtemplate>
</asp:templatefield>
</columns>
</asp:gridview>

i binded the values

but how to update the values at a stretch with a single button

how to do this..

knortix  Tuesday, August 01, 2006 10:44 AM
use <asp:CommandField> in <columns> to update,edit or delete.
Mohan Raju  Wednesday, November 08, 2006 12:34 PM
Hi, I have the same problem, i did what you say.
But how i can get the value of this Textbox using c#

TextBox x = (TextBox)GridViewCarrinho.Rows[row.RowIndex].Cells[2].FindControl("txtQuantidade");

It doesn't works.
Thanks
james47  Thursday, September 25, 2008 2:27 PM

I don't understand how to solve this problem:

mi code in the aspx is:

<asp:GridView ID="serviciosList" AllowPaging="True" CellPadding="3" GridLines="Vertical"

AutoGenerateColumns="False" runat="server" AllowSorting="True" BackColor="White"

BorderColor="#999999" BorderStyle="None" BorderWidth="1px" Width="676px"

Height="100px">

<FooterStyle ForeColor="Black" BackColor="#CCCCCC" />

<PagerStyle ForeColor="Black" HorizontalAlign="Center" BackColor="#999999" />

<HeaderStyle ForeColor="White" Font-Bold="true" BackColor="#000084" />

<Columns>

<asp:BoundField HeaderText="Clave" DataField="clave_servicio">

<ItemStyle HorizontalAlign ="Center" VerticalAlign="Middle" />

</asp:BoundField>

<asp:BoundField HeaderText="Descripcion" DataField="descripcion">

<ItemStyle HorizontalAlign ="Left" VerticalAlign="Middle" />

</asp:BoundField>

<asp:BoundField HeaderText="Unidad Medida" DataField="unidad" />

<asp:BoundField HeaderText="Costo" DataField="costo" DataFormatString="{0:c}">

<ItemStyle HorizontalAlign ="Right" VerticalAlign="Middle" />

</asp:BoundField>

<asp:TemplateField HeaderText="Cantidad">

<ItemTemplate>

<asp:TextBox ID="txtCantidad"

AutoPostBack="false" runat="server" Width="30px" OnItemCommand="RecordOperate" CssClass="etiqueta" Enabled="true" />

</ItemTemplate>

</asp:TemplateField>

</Columns>

<SelectedRowStyle ForeColor ="White" Font-Bold ="True" BackColor="#008A8C" />

<RowStyle BackColor="#EEEEEE" ForeColor="Black" />

<AlternatingRowStyle BackColor="#DCDCDC" />

</asp:GridView>

in this, i have a textbox to cach a items to select

my code to show the item selected

Protected Sub ok_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OkButton.Click

Summary.Text = "Monto de la requisicion : <ul>"

Dim currentRowsFilePath As String = String.Empty

Dim valor As String = String.Empty

For index As Integer = 0 To serviciosList.Rows.Count - 1

Dim txt As String = CType(serviciosList.Rows(index).Cells(4).FindControl("txtCantidad"), TextBox).Text

summary.Text = txt

Next

summary.Text &= "</ul>"

End Sub

so, txt it's blank, somebody know why?

thank's

alexito1965  Tuesday, December 09, 2008 11:28 PM

You can use google to search for other answers

Custom Search

More Threads

• Binding Grdview to BindingSource
• Creating Update and Search buttons
• DataGridViewComboBoxColumn Problem
• Data Grid Bound to DateTimePicker Control?
• Unable to simply remove the current DataGridView textbox entry
• datagridview problem
• DataGrid Checkbox: Immediate check/uncheck whilie clicking on it
• datagridview
• Re: Can't set the SelectedValue of a ComboBox after databinding
• filling a dataset from a recordset