473,388 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Loop through textbox in template field

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 2598
nateraaaa
663 Expert 512MB
    1. // this is where is should get the texbox value
    2. entity.RatingValue = masterPage.BindUIControlsToObject(entity, gvwData.FooterRow.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. skillSetDatabaseBL.Insert(entity)
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.RatingValue 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
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
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...
3
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... ...
4
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...
2
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...
6
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 =...
7
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...
3
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....
2
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.