How to add values to template control fields textbox control in GridView..

Hi all,

    <asp:GridView ID="GridView1" EnableViewState="true" DataKeyNames="LicenseTemplateID"
                       runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
                                   <asp:CheckBox  EnableViewState="true" ID="rdbBatchTime" runat="server" OnCheckedChanged="SelectOnlyOne"></asp:CheckBox>
                           <asp:BoundField DataField="Name" HeaderText="LicenseType" InsertVisible="False" ReadOnly="True">
                               <ControlStyle Width="150px" />
                           <asp:TemplateField  HeaderText="Currency">
                                   <asp:TextBox Width="35px" EnableViewState="true" ID="_currency" runat="server" MaxLength="2"></asp:TextBox>
                           <asp:TemplateField HeaderText="Price">
                                   <asp:TextBox Width="60px" EnableViewState="true" ID="_price" runat="server" MaxLength="4"></asp:TextBox>

 i have designed the grid as shown above. My requirement is to add some value (any value) in to textbox of gridview. Please let me know how to do it. The value should be added on page load or on drop down index changed event. its urgent.



1/3/2007 6:28:45 AM 93655 articles. 5 followers. Follow

5 Replies

Similar Articles

[PageSpeed] 47

If you want a value from a datasource to be in the TextBox you can use the <%# Eval("<field>" %> or Bind expression. You can also hook up to the RowDataBound event of the GridView and set the value of a control inside a cell in a row.
/Fredrik Normén - fredrikn @ twitter

Microsoft MVP, MCSD, MCAD, MCT

My Blog
1/3/2007 6:36:02 AM

Hello sir,

      I want to add the values to textbox of template control in grid in the codebehind page and i dont want the value from the datasource like as you told to use <%# Eval("<field>" %> or other option. Please help me..



1/3/2007 6:44:00 AM

This post on my blog will not give you code to set a value on a TextBox, but will show you how you can use the RowDataBound event to get access to a control in the GridView and change a controls value.

It will at least give you the solution to access controls in the codebehind when the Row is databound. You can also after the whole grid is created access each row and change a specific row's cell.. but I assume you want to give a value for each row and I think a good place to do it is in the RowDataBound event.

/Fredrik Normén - fredrikn @ twitter

Microsoft MVP, MCSD, MCAD, MCT

My Blog
1/3/2007 6:55:00 AM

You need to write your code in the RowDataBound event of the GridView.

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    if (e.Row.RowType == DataControlRowType.DataRow)
       TextBox _txtPrice = (TextBox) e.Row.FindControl("_price");
       if (_txtPrice != null)
          _txtPrice.Text = "some text"; // set your text here


Mark post(s) as "Answer" that helped you

Electronic Screw
1/3/2007 8:19:14 AM


if you wanna add the value to the all the textboxes in the Page_Load event, do just as e_screw suggested.

if you wanna add the value to a single textbox in the DDL selectedIndexChanged event, using the following


 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        TextBox tb = (TextBox)GridView1.Rows[1].Cells[2].FindControl("_currency");
        tb.Text = DropDownList1.SelectedValue;

hope it helps


Jessica Cao
Microsoft Online Community Support

“Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”
1/4/2007 4:14:21 AM

Similar Artilces:

How to add a Web server or HTML server controls (such as CheckBox) to the template in GridView and bind the controls to a data source.
How to add a Web server or HTML server controls (such as CheckBox) to the template in GridView and bind the controls to a data source. Normally, We can add a Web server or HTML server controls to the template in GridView control,just like the Code 1I hope to do the same thing by programming (just like the Code 2), but I can ony add the BoundField,I don't know how to add a CheckBox control to the template in GridView , could you help me? //--------------------------------------------Code 1------------------------------------------------------------<asp:GridView AutoGenerateColumns="False...

Add .Net Control to Web Custom Control
 I want to add .NET Control (like: TextBox, Button...) to Web Custom Control.How i can do it? Alphavn That's called a composite control -- "Mark As Answer" if my reply helped you -- Hello Guys What gunteman said, that is one approach and in most cases the right one.But its also possible to add child controls to a Control thats inherit from WebControl itself. Be sure to implement INamingContainer to that inherited Control too, thats the important point of that approach.--Microsoft MVP - Visual Developer ASP / ASP.NET-

TextBox values to Gridview control Add?
 Hi Everyone. Simple stuff, but I am not able todo yet. here is the markup <body>     <form id="form1" runat="server">     <div>         <asp:TextBox ID="TextBox1" runat="server" />&nbsp;         <asp:DropDownList ID="DropDownList1" runat="server" />&nbsp;         <asp:Button ID="btnAdd" runat="server" Tex...

Add controls in textbox ( TextBox1.Controls.Add(); )
hi to alli want to know about TextBox1.Controls.Addit is possible to add controls in a textbox like placeholder i am using  this much of code for add linkbutton in a textbox 1 LinkButton lb = new LinkButton();2 lb.Text = "Linkbutton1";3 lb.ID = "link1";4 5 TextBox1.Controls.Add(lb);6 7 Response.Write (TextBox1.Controls.Count);8 Response.Write(TextBox1.Controls.ToString());this code run without any error when i count a control in textbox then it will disply me a 1 but on the page it will not display any controls in a textbox if this is...

Controlling web control instances on Web Form
I have created a composite control, extending functionality of the Hidden Control. However, I would like to prevent the user from adding this control to the page multiple times. I only want one instance of the control on the Web Form. What setting in my project to I adjust to enable this functionality? I can not find it in any of the books that I have referenced. Is this a setting or is this code that has to be added to the inheriting class. Looks like there is no standard apporach. But I'd consider using static field to count number of created objects and throw exception if second object ...

when loading a previously created record on to form, some controls are missing values(controls are depended on values selected in other controls)
Hello - I have created a page for Editing records.  this page will open up a chosen record and allow user to edit the data.On the form, I have 3 drop down lists.   The second dropdown list should fill values depending on value chosen in first dropdown list.  The third dropdown list should show/fill values depending on value chosen in second dropdown list.So taking this into count, i have several records with various data.  When I open-up/load a record in Edit form, only the first dropdown list has a value selected that was the pre-existing va...

There is a Gridview Control in the tmplate field of another GridView Control.
    For instance,a gridview displays the information of the  students in a class.A table is recording the information except their mark.There is another table recording the mark of the students whose foreign key is the primary key of the previous table.   string strSQLconnection=".................."; SqlConnection sqlCononection=new SqlConnection(strSQLconnection); SqlCommand sqlCommand=new SqlCommand("select * from stuendent where classID=1",sqlConnection); SqlConnection.Open(); SqlDataReader reader=sqlCommand.ExecuteReader(); GridVie...

how to call controls of web control form in coding of other forms?
hello everyone i have one problem i have created one webcontrol shoppingcart in which there are two labels one of qty and other of amt which are initially enable =falsenow on other page(aspx page) i have one txtbox of qty as txtqty i want tat as soon as user enters qty txtqty and clicks on add cart button it shd be display d value in lblqty of web control shopping cart make sure i m using datalist on aspx page so give me suggestions on tat basis and my coding is in vb. plz give ur suggestions as fast as possible. Neeti what do you mean by webcontrol.... it this user control or normal ...

How can I add a validation control to a textbox <EDITITEMTEMPLATE> control for a gridView
How can I add a validation control to a textbox <EDITITEMTEMPLATE> control for a gridView and referenece it properly? ThanksJeff Wasilauski, MCAD .NET, MCPC# WEB DEVELOPMENT-SQL SERVER DBA"If I have answered your question please mark as answer" Hi,jwaz1999:Here is the totorial you can follow: Regards,__________________________________________________Sincerely,Rex LinMicrosoft Online Community SupportThis posting is provided "AS IS" with on warranties, and confers no rights. Thanks for your reply Rex.&n...

GridView child of GridView
I have a Parent GridView and when you click in the Edit one of the columns has a Template Field which has a Child GridView. When you click Edit on the Child GridView I have a Template Field that has a TextBox. How to I retreive this value of the TextBox? GridViewParent-- GridViewChild (Edit - Template Field containing this GridViewChild)----- TextBox inside Template Field in GridViewChild. Thank you.Peace in ChristMarco Napoli What you can do as a solution is to override the RowDataBound and try to find the child GridView control. Once you get a reference to...

How to access individual controls from a form containing the web user control containing those controls
 Below is a block of code in my .aspx form named default.aspx. In this form I load a web user control. I then add it to a place holder control.(Lines 3 and 4 below) So how do I access the individual controls in my web user control? I want to set the properties on those controls, but I am baffled as to how to access the control. For example I have a text label control named "label3". How do I access this control. Because for example, under certain situations I want to hide that control. ( Label3.Visible = false;)  1    if(!Page.IsPostBack) 2&nb...

Setting Properties in web controls within GridView template fields
I have a list of items in a gridview: Col 1 is lesson number (1 to N always)Col 2 is lesson titleCol 3 is a template field with 4 image buttons with CmmandNames I handle the button clicks in the RowCommand handler. One of the buttons is a "Move Up" button, the other is a "Move Down" button.  Naturally, when you click "Move Up" for the first item, it will do nothing (checked in the stored procedure called in the RowCommand handler).  Likewise, clicking on "Move Down" on the last row (can be on a separate page - paged gridview) does nothing (also checked for in the stored procedru...

Web control in web control
Hi,There are two simple web user controls A and B, where B contains A. They just display the bunch of text boxes, so I do not need them even in tool pane. They sit in the same project next to web form.I noticed that web user control put on ASPX page does not appear in code behind, but if I create it with protected keyword and name being exactly the same as id it works fine. I can access such a web control from code behind and see the value assigned in IE. The problem is that the same routine does work for my A web control in B. When I assign the value IE, I keep getting null reference. ...

How to get cell values when GridView is bound with Template Control Fields
Hi, I have following GridView <asp:GridView ID="gdvProcAdmin" runat="server" AutoGenerateColumns="false" AllowSorting="true"> <Columns> <asp:TemplateField HeaderText="ID" Visible="false"> <ItemTemplate> <asp:Label ID="lblID" runat="server" Text='<%#Eval("ID")%>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Category" SortExpression="Type"> <ItemTemplate> <asp:Lab...

Web resources about - How to add values to template control fields textbox control in GridView.. -

Template - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Facebook page template & tips for 2014
As Facebook page admins get started with 2014, the social marketing experts at ShortStack created a detailed template , including image sizes, ...

Frame Artist Pro - Best Photo Collage Editor, Stitch Your Photos with Pic Frame Templates & Filter Effect ...
Get Frame Artist Pro - Best Photo Collage Editor, Stitch Your Photos with Pic Frame Templates & Filter Effect & Frames on the App Store. See ...

Paper wireframe templates - Flickr - Photo Sharing!

United Airlines accidentally sends letter template to unhappy passenger
A US air passenger may have received what is quite possibly the world’s least sincere apology letter.

TV Templates - Transcripts
Lorem ipsum dolor sit amet, aihiad adaph dpas, osaf das. Oi asdfpo ijafj ai.

Mockup Apple Watch apps and compare screen sizes with these official bezel templates
... for developers, readers interested in Apple Watch can also use the images to compare the overall physical size of the two sizes. The templates ...

Paper by FiftyThree makes starting new projects easier with templates
... FiftyThree has just received an update that significantly improves various aspects of its interface and functionality. Get started with templates ...

Windows 10 patch messing with your Office 2016 templates? Here's how you can get them back
... 10 patch has had some Word 2016 users cringing in despair. The patch, titled Cumulative Update KB3124200 , is causing the Word 2016 template ...

Templates, Insights and Dictation in Google Docs
Google's standalone web apps for Docs , Sheets and Slides now show a list of templates you can choose to quickly create a document, spreadsheet ...

Resources last updated: 1/19/2016 9:41:50 AM