473,804 Members | 3,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Loop through textbox in template field

3 New Member
Hi All,

I really need help to solve my problem.
My case is on looping through textbox in gridview.
I had a gridview placed in my page. The gridview contains template field
which I created it during runtime. I also had a generic list to fetch few items. Number of item that i got from the list will be the number of template that being created during runtime(eg : if the list return 3 items, meaning there will be 3 template field created).
The problem arise when I place each template field with tbox control. Im not able to loop through template and find the tbox control inside it as it(tbox) doesnt have ID yet. I cannot name the tbox ID as each tbox would have multiple ID name soon. Below I had attached my code for u to take a look.Hope anyone can give solution.

I called the BindTemplate method under page load
Expand|Select|Wrap|Line Numbers
  1. public void BindTemplate()
  2.         {
  3.             SkillSetBL skillsetBL = new SkillSetBL();
  4.             List<SkillSet> list = new List<SkillSet>();
  5.             list = skillsetBL.GetSkillType();
  6.  
  7.             SkillSet[] empArray = list.ToArray();
  8.  
  9.             foreach (SkillSet item in empArray)
  10.             {
  11.                 string a = item.ID.ToString();
  12.  
  13.                 TemplateField templateField = new TemplateField();
  14.                 templateField.HeaderText = item.SkillName.ToString();
  15.                 gvwData.Columns.Add(templateField);
  16.  
  17.                 templateField.FooterTemplate = new TextboxTemplate();
  18.                 templateField.ItemTemplate = new LabelTemplate();
  19.  
  20.             }
  21.         }
  22.  
  23. private class TextboxTemplate : ITemplate
  24.         {
  25.             public void InstantiateIn(System.Web.UI.Control container)
  26.             {
  27.                 TextBox tbx = new TextBox();
  28.                 tbx.Width = 12;
  29.                 tbx.DataBind();
  30.                 container.Controls.Add(tbx);
  31.             }
  32.         }
  33.  
  34.         private class LabelTemplate : ITemplate
  35.         {
  36.             public void InstantiateIn(System.Web.UI.Control container)
  37.             {
  38.                 Label lbl = new Label();
  39.                 lbl.DataBind();
  40.  
  41.                 container.Controls.Add(lbl);
  42.             }
  43.         }
  44.  
my problem is at this stage
Expand|Select|Wrap|Line Numbers
  1. protected void gvwData_RowCommand(object sender, GridViewCommandEventArgs e)
  2.         {
  3.             GridViewRow row = gvwData.FooterRow;
  4.  
  5.  
  6.             if (e.CommandName == "Insert")
  7.             {
  8.                 SkillSetDatabase entity = new SkillSetDatabase();
  9.                 SkillSetDatabaseBL skillSetDatabaseBL = new SkillSetDatabaseBL();
  10.  
  11.  
  12.                 try
  13.                 {
  14.                     if (((DropDownList)row.FindControl("ddlstEmployeeID")).SelectedValue == "")
  15.                     {
  16.                         _masterPage.GetNotifyLabel().Text = "Employee name is not selected. Please provide related information.";
  17.                     }
  18.                     else
  19.                     {
  20.  
  21.                         entity.Creator = Convert.ToInt16(Session["Creator"].ToString());
  22. // this is where is should get the texbox value                       
  23.                         entity.RatingValue = masterPage.BindUIControlsToObject(entity, gvwData.FooterRow.Controls);
  24. //before insert new record, i have to iterate the template field to find textbox, and then during the iteration only the ID of tbox be given
  25.                         skillSetDatabaseBL.Insert(entity);
  26.  
  27.  
  28.                         _masterPage.GetConfirmLabel().Text = "New record added.";
  29.  
  30.                         gvwData.DataBind();
  31.                     }
  32.  
  33.                 }
  34.                 catch (Exception ex)
  35.                 {
  36.                     throw new Exception(ex.Message);
  37.                 }
  38.             }
  39.  
  40.  
  41.         }
Mar 14 '08 #1
1 2623
nateraaaa
663 Recognized Expert Contributor
    1. // this is where is should get the texbox value
    2. entity.RatingVa lue = masterPage.Bind UIControlsToObj ect(entity, gvwData.FooterR ow.Controls);
    3. //before insert new record, i have to iterate the template field to find textbox, and then during the iteration only the ID of tbox be given
    4. skillSetDatabas eBL.Insert(enti ty)
I have a few questions about what you are trying to accomplish. Will there be multiple textboxes in the same gridview row? If so how will you set entity.RatingVa lue for each textbox? Is RatingValue a type that can hold multiple values? Assuming you can do all of the above will the value for each textbox be saved in the same column or different columns in your database?

Nathan
Mar 14 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2797
by: Vijaya | last post by:
Can we bind data to textbox in a headertemplate in a template column of a datagrid? If so please give some code snippets. Thank you
7
3458
by: Cemal Karademir | last post by:
Hello, Please forgive my simple question, but i don't know the correct synatx. From the masterpage i want to put a text in an textbox and then select an item in the datagrid. I do know how to pass the items in the datagrid(e.g. PLU, description, etc.) to an other (detail)page, but i don't know the correct syntax of how to pass the textbox value to the detailpage. I have the following code:
3
2247
by: Neil Zanella | last post by:
Hello, I have a bunch of HTML input controls which I need to generate from within a for loop. I would like them to have id attributes set to values foo1, foo2, foo3, foo4, etc... Unfortunately it seems this is not possible because ASP.NET won't let me use ASP tags within the values of the id attribute. So for instance I cannot just do the following:
4
3584
by: Luqman | last post by:
How can I display any field value in textbox of sqldatasource using VS.Net 2005 ? Say : Dim x as new AccessDataSource X.connectionstring="Data source="D:\mydb.mdb" X.Selectcommand="Select CompanyName from customers" Textbox1.text= ??? <-------- I need to display CompanyName Field in this textbox, how can I ?
2
1331
by: davidw | last post by:
I have flat xml like this <field name="a1"/> <field name="a2" merge="true"/> <field name="a3"/> <field name="a4"/> <field name="a5" merge="true"/> <field name="a6" merge="true"/> <field name="a7"/>
6
2281
by: david | last post by:
I try to use "for" loop to retrieve and assign values in web form. The code is in the following. But it can not be compiled. What I want to do is: txtQ1.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q1") txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2") ..... txtQ10.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q10") ------code ------- Dim field As String = "Q"
7
9784
by: david | last post by:
I try to use "for" loop to assign textbox control ID to a textbox variable in server side codebehind for a web form. But I met some problem. What I want to do is solving the following-like code by a loop: static code: txtQ1.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q1") txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2") ..... txtQ10.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q10") where Q1, .. Q10 are field name of a table; and...
3
2888
by: keithb | last post by:
My code dynamically adds template fields to a GridView control. Everything seems to work OK, except when updating, because I haven't found a way to reference the dynamically added textboxes. FindControl doesn't work, and the textboxes cannot be accessed using grid.Rows.Cells.Control. Can someone help? Thanks, Keith
2
3715
by: Steve | last post by:
One of the columns in my gridview is a blank textbox (I have added it as a template field). Users can enter a number in the textbox for a multiple of the gridview records. I have a submit button which is intended to use code behind to access these textbox values and eventually add them to a database. However, I can't seem to loop through the textboxes in the gridview successfully and store their values. Does anyone know the right...
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10588
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7623
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5527
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5662
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4302
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.