473,503 Members | 10,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB-WEB: Difficulties with ItemTemplate CheckBox ID

3 New Member
I am looking to do something like this to assign a unique ID to each checkbox in a gridview:

Expand|Select|Wrap|Line Numbers
  1. <asp:TemplateField Visible="False" HeaderStyle-CssClass="SpreadSheetHeader" ItemStyle-CssClass="SpreadSheetCell" ShowHeader="True" HeaderText="Add to Cart / Qty" >
  2.                         <ItemTemplate>
  3.                             Add?<asp:CheckBox ID='<%# Eval("DFNumber") %>' CssClass="chkOrder" runat="Server" />
  4.                             Qty:<asp:TextBox CssClass="txtBoxQuantity" ID="txtQuantity" runat="server"></asp:TextBox>
  5.                         </ItemTemplate>
  6.                     </asp:TemplateField>  
But I get the error message 'server tag is not well-former'. Is it possible to do it like this? If not, what would be a good way to assign a unique ID to a checkbox control in an item template?
Jul 28 '08 #1
1 1159
Frinavale
9,735 Recognized Expert Moderator Expert
I remember attempting to do the same thing that you are trying to do. I discovered that it isn't possible..and at one point had a good reason as to why this is but can't remember it off the top of my head.

Because the controls are dynamically given an ID anyways, why don't you just give the CheckBox an ID like "ChkboxAdd", and include a hidden column called something like "DFNumber" that will keep track of what DFNumber you are "adding".

EG
Expand|Select|Wrap|Line Numbers
  1.       <asp:TemplateField Visible="False" HeaderStyle-CssClass="SpreadSheetHeader" ItemStyle-CssClass="SpreadSheetCell" ShowHeader="True" HeaderText="Add to Cart / Qty" >
  2.                               <ItemTemplate>
  3.                                   Add?<asp:CheckBox ID='ChkboxAdd' CssClass="chkOrder" runat="Server" />
  4.                                    Qty:<asp:TextBox CssClass="txtBoxQuantity" ID="txtQuantity" runat="server"></asp:TextBox>
  5.                               </ItemTemplate>
  6.                           </asp:TemplateField>
  7.                           <asp:BoundField Header="DFNumber" DataField="DFNumber ">
  8.                            <ItemStyle CssClass="noShow" width="0px">
  9.                            <HeaderStyle CssClass="noShow" width="0px">
  10.                           </asp:BoundField>
  11.  
Then in your code that does "stuff" loop through the rows in the gridview, grab the checkbox check value and the DFNumber for that row....and do your processing on that:

Expand|Select|Wrap|Line Numbers
  1. For Each dr In MyGridView.Rows
  2.        Dim chkBox as CheckBox=Ctype(dr.FindControl("ChkboxAdd"),Checkbox)
  3.        If chkbox.checked = true then 
  4. 'Here retrieve the DFNumber for the row that has been "checked".
  5.        End If
Jul 28 '08 #2

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

Similar topics

16
486
by: Terry | last post by:
Hi, I need some feedback. We are converting to .Net and we are trying to decide on whether to use VB.net or C#.net. As far as our current systems, they will probably be rewritten in ASP.Net. I...
13
5132
by: Arsalan | last post by:
Is there any advantage in C# over VB.NET ? Or the difference is only syntax ? Can anything done in C# which cannot be done in VB.NET?
72
3405
by: Robin Tucker | last post by:
I need to find some documents/research for my manager about VB.NET v C# use. I've noticed that there are many more people using C# than VB.NET, that there seem to be more job vacancies specifying...
28
2419
by: Andy | last post by:
Any good resources regarding benefitis by using C3 over VB? /Andy
12
1639
by: Leo Muller | last post by:
I always thought that moving from VB.NET to C# would be very easy. Even though so far it hasn't been hard, there are some annoying things, that may have to do with my visual studio settings. -...
16
2565
by: Ben Hannon | last post by:
Hi, I'm writting a COM Class in VB.NET to be used in a VB6 project (Tired of the VB6 hassles with cloning and serializing an object). All my classes I need cloneable/serializable are now in a...
182
7356
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
25
1793
by: Sharrukin Amiri | last post by:
Hello, I am using VB 6.0 for many years. Everytime I needed to build software applications, I just opened VB 6.0 and started coding. I am now looking VB.NET Express Edition and I find I can no...
2
1671
by: D H | last post by:
Hi, Hi, I was looking for your opinion on VB.NET - its long-term prospects, etc. Sorry this is vague, but it's not meant to be a troll. It's a pro-VB.NET post actually. I haven't used VB or...
0
7095
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
7294
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,...
1
7015
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...
1
5026
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...
0
4693
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...
0
3183
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...
0
3173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1523
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 ...
0
403
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...

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.