Adding Textbox to a Gridview

I am using a GridView to get data from a datasource. I want to add a textbox at the end of each column in the GridView i.e at the footer How do I do that?

-------------Problems Reply------------

Use FooterTemplate. Example:

<asp:TemplateField>
<ItemTemplate>
...
</ItemTemplate>
<FooterTemplate>
your textboxes go here
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
...
</ItemTemplate>
<FooterTemplate>
your textboxes go here
</FooterTemplate>
</asp:TemplateField>

You should understand the differences between the BoundField and the TemplateField class. The first is used to display fields as a text, while in the TemplateField you can customize the way you're going to display the information. So, you should use BoundField or TemplateField in a column (not one nested inside another as I think you're trying), in your case it has to be the TemplateField, because you want to customize the way your footer shows up. So, it should be something like this:

<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="lblNumber" runat="server" Text='<%# Bind("Number")%>' />
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txb" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>

Add TextBox in <FooterTemplate>

<asp:TemplateField HeaderText="UnitsInStock">
<ItemTemplate>
//your displaying control
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="tb1" Text="Text" runat="server" />
</FooterTemplate>
</asp:TemplateField>

Find footer control in OnRowDataBound event:

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Footer)
{
TextBox tb1 = (TextBox)e.Row.FindControl("tb1");
//do your stuff
}
}

Category:asp.net Views:0 Time:2012-04-15
Tags: asp.net

Related post

  • How to add a Textbox to Dynamic GridView 2009-12-04

    How do I add Textbox to a dynamic Gridview. Do I need to have a customised Templete Field ? Is there any other way ?? --------------Solutions------------- Do you mean you want to dynamically generate rows with TextBoxes in a GridView? If so, then the

  • How to retrieve data from dynamically added textboxes? 2008-10-23

    Im adding textboxes (not a fixed number of textboxes) dynamically to a form on ASP.NET page, how do i read back data from these textboxes? --------------Solutions------------- Assuming you're wanting to access the controls on the postback you'd proba

  • javascript php get value from a dynamically added textbox 2009-09-07

    i'm using this to generate a textbox dynamically:` <html> <head> <title>Dynamic Form</title> <script type="text/javascript" > function CreateTextbox() { var i = 6; createTextbox.innerHTML = createTextbox.innerHTML +"<

  • How can I make a TextBox in a GridView not fire TextChanged when SelectedIndexChanged is fired? 2010-06-21

    I have a TextBox in a TemplateField in a GridView that is supposed to show a checkmark after its TextChanged event. I also made the GridView row selectable. If I select a row, the entire GridView rebinds and fires the TextChanged event for all TextBo

  • gwt dynamic adding textbox 2010-11-15

    @UiHandler("addDynamicTextboxbutton") void addMoreTextbox(ClickEvent event) { textboxplaceholder.add(new TextBox(),"textboxplace"); } when addDynamicTextboxbutton button is clicked, this method is executed and new textbox is created. how to have anot

  • JavaScript Validation to TextBox in a GridView in ASP.Net 2011-06-06

    I have a GridView in Which I have four TextBoxes in the Template Field. I have one Button below the GridView. How to validate the TextBoxes in the GridView, When the Button Clicked? --------------Solutions------------- use RequiredFieldValidator and

  • Validate the TextBoxes in the GridView based on a value in ASP.Net 2011-06-08

    I have a GridView whose columns names are ID, Name, Price, Tolerance, Remarks and Value_f. I have TextBoxes in the Template Field for Price, Tolerance and Remarks. I have one Button called "Save Button" below the Gridview. I bind the values for ID, N

  • C# : Dynamically added Textbox has URL issue 2011-10-19

    I have written a piece of code in C#. That is, dynamically adding TextBoxs to edit data coming from database. I am getting issues if the data contains URLs. I need to show the data in textboxs as it is in database, but I am getting appended hyperlink

  • Selecting last dynamically added textbox 2012-01-16

    I have a list of input boxes with dates (and the class name "newDate") in them and I can add more of them dynamically. When i try to get the value of the last added textbox, I always end up with first, which was a textbox rendered with the page. $(".

  • ASP.NET MVC3: Adding Textboxes with Jquery and binding to Model 2012-04-03

    I have created a View which prompts the user to input some records with an invoice number and save them to the DB. Now a new requirement came in, we must be able to save 1..N invoice numbers for one record. No problem in the database, but I cant find

  • UserControl causing loss of textbox content in Gridview header 2008-12-11

    All, My problem is that my gridview header that contains textboxes etc. that users can type into is somehow losing the content of those textboxes when the user forces a postback - but only if I have a user control in the header. This is using .NET 2.

  • Programmatically insert a TextBox control into GridView.FooterRow 2009-01-29

    You can modify the columns and the ItemTemplate of columns in a GridView's HeaderRow. But the same is not possible on the FooterRow since it's read-only. Is there any way that I can programmatically add a TextBox control to a FooterRow in a GridView

  • maintaining the state of Newly added row in custom gridview. on postback 2009-11-12

    I have a custom gridview on rowdatabound i am adding new gridviewrows . but on postback the data in newly added row is not persists. Please help me to maintain the state of grid on postback as well...Actually i m showing group header rows and footer

  • adding textboxes at runtime in asp.net 2010-01-28

    i need to create textboxes dynamically as user specifies the no..actually there are two textboxes in a row..user specifies no of rows needed.. as specified textboxes(two per row) should be added to the form and also i need to read the text entered la

  • To bind value in TextBox field of GridView 2010-12-30

    I have one form in which GridView contains 1 "rate" field in TextBox. The rate field is not added to database. Now on another form (report generation), in GridView i want to show the value of the rate field which is in first form, How can i do this?

  • TextBox column in GridView 2011-03-15

    I added a textbox column in the gridview by using the following code. <asp:TemplateField HeaderText="Order"> <ItemStyle/> <ItemTemplate> <asp:TextBox ID="txtPriority" runat="server" width="15px" /> </ItemTemplate> </a

  • Read a dynamically created textbox in a Gridview 2011-05-09

    I am dynamically adding a textbox to certain rows (one column only) of a gridview. I add the controls with this insdie of a test condition (works fine): TextBox txtASIN = new TextBox(); txtASIN.ID = "TxtASIN" + e.Row.RowIndex; e.Row.Cells[4].Controls

  • adding textboxes to panel in modal popup 2011-10-12

    How can I dynamically add text boxes to a Panel in a modal popup? I am trying this so far with no luck.... There is a gridview that pops up a modal panel where I would like to dynamically add textboxes. UPDATED CODE IN FOR LOOP: int num = 4; int I; /

  • Adding data to database ( gridview ) , refresh gridview to see the values? 2012-03-15

    I have a gridview. I'm adding values with parameters->open connection->execute reader->connection close But the problem is that the values added are not displayed in the gridview and if I reload the page I still can't see them but if I click

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.200 (s). 11 q(s)