473,748 Members | 3,823 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Trouble referencing controls within list controls

I have a DataGrid containing a TextBox control and a CustomValidator
in each row. The CustomValidator fires a function that compares all
TextBoxes for equality. The algorithm for comparison is
straightforward :

*PSEUDOCODE*

for i=1 thru ( Container.Lengt h-1 )
for j=i+1 thru ( Container.Lengt h-1 )
if ( TextBox[i]==TextBox[j] )
TRUE

It would be even faster if instead of starting with 1 everytime, I set
i to get the index of the current Container row.

Problem is I'm having trouble referencing the TextBoxes within the
DataGrid. I've studied msdn
(http://msdn.microsoft.com/library/de...formspages.asp)
but the concept still baffles me.

Specifically, what I try to do is store the TextBoxes for comparison
in an array:

Dim ControlName As String ' temporary

ControlName = OurDataGrid.Con trols(i).Unique ID
aObjFirst(0) = CType( Me.FindControl( ControlName & "First"), TextBox
)
ControlName = OurDataGrid.Con trols(j).Unique ID
aObjFirst(1) = CType( Me.FindControl( ControlName & "First"), TextBox
)

' If first names match...
If ( aObjFirst(0).Te xt=aObjFirst(1) .Text ) Then
...

(Yes, I'm comparing first names.) However, this always warns me that
j is out of range. And getting back to the msdn, it seems to be
discouraging the technique of name concatenation I used to get at the
controls I want.

Can anyone follow where I'm going with this and provide some
insightful direction?
Nov 18 '05 #1
3 1678
--or a totally different approach would be welcome. Anything that
could help, really.

I just thought of a less repetitive algorithm.

Provided I can dynamically obtain the index of the current row:

*PSEUDOCODE*

for i=currentIndex thru ( DataGrid.Contro ls.Count-1 )
if ( TextBox[currentIndex].Text==TextBox[i].Text )
TRUE

Problem is I still need help referencing the individual TextBox
controls that my DataGrid generates. I have a feeling the solution
lies with the UniqueID property, but I still can't solve it on my own.
I have a DataGrid containing a TextBox control and a CustomValidator
in each row. The CustomValidator fires a function that compares all
TextBoxes for equality. The algorithm for comparison is
straightforward :

*PSEUDOCODE*

for i=1 thru ( Container.Lengt h-1 )
for j=i+1 thru ( Container.Lengt h-1 )
if ( TextBox[i]==TextBox[j] )
TRUE

....
Specifically, what I try to do is store the TextBoxes for comparison
in an array:

Dim aObjFirst(2) As TextBox
Dim ControlName As String ' temporary

ControlName = OurDataGrid.Con trols(i).Unique ID
aObjFirst(0) = CType(Me.FindCo ntrol(ControlNa me & "First"), TextBox)
ControlName = OurDataGrid.Con trols(j).Unique ID
aObjFirst(1) = CType(Me.FindCo ntrol(ControlNa me & "First"), TextBox)

' If first names match...
If ( aObjFirst(0).Te xt=aObjFirst(1) .Text ) Then
...

(Yes, I'm comparing first names.) However, this always warns me that
j is out of range. And getting back to the msdn, it seems to be
discouraging the technique of name concatenation I used to get at the
controls I want.

Can anyone follow where I'm going with this and provide some
insightful direction?

Nov 18 '05 #2
Same question, different day, (hopefully) worded more clearly.

I have a DataGrid containing a TextBox control and a CustomValidator in
each row.

The CustomValidator fires a subroutine that compares all TextBoxes the
DataGrid generates for equality.

The algorithm is pretty straightforward :

*PSEUDOCODE*

senderIndex = the row in the DataGrid of the sender
FOR ( i=senderIndex+1 ) THRU ( last Row of the DataGrid )
IF ( TextBox[i].Text==TextBox[senderIndex].Text )
TRUE

However, I'm stuck in my attempts to formally code this algorithm:
*CODE*

Sub HasDupe(sender as Object, e as EventArgs)
Dim objFirst As Textbox
value.IsValid = False

For ( i = SENDER_INDEX+1 ) To ( DataGrid.Contro ls.Count-1 )
' get the control in row i with the same ID as the
sender
objFirst =
OurDataGrid.Ite ms(i).FindContr ol(sender.Contr olToValidate)

If ( objFirst.Text=s ender.Text )
value.IsValid = True
End If
Next
End Sub
I /think/ my only problem is the "SENDER_IND EX"--I can't figure out how
to reveal the row number of the sender. This is my question.

(But if any other part of my code looks screwy, I'd appreciate input on
that as well.)

Nov 19 '05 #3
(Here's an answer I received from another post, that _works._

--E.)

Use can use the parent control to find the index. All Controls have
parents and children, you can move up and down the node list to find
the one you are looking for. You can shorten the code, I just wanted to
make sure you saw the levels. Also a while back I was trying to deal
with CustomValidator s in datagrids, I seem to recall some issues with
that just FYI. Hope this helps AuSable Troutbum
'Find the The control that is firing event
Dim valCustomContro l As New CustomValidator
valCustomContro l = sender
'Find the Parent Cell of Validation Control
Dim cell As TableCell = valCustomContro l.Parent
'Find the Datagrid Item
Dim dgItem As DataGridItem = cell.Parent
'Set the Row
Dim myRow As DataRow =
DataSet.Tables( "YourTableName" ).Rows(dgItem.I temIndex)

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1781
by: mystical_potato | last post by:
From VS.NET 03 AND VB.NET I added a dropdown list to a data grid control in response to the EditCommand event to force users to pick values from a list and not type them in. I used the following code: 'Hide the existing txt box Dim txt As TextBox txt = CType(e.Item.Cells(0).Controls(0), TextBox) txt.Visible = False
0
293
by: 2obvious | last post by:
I have a DataGrid containing a TextBox control and a CustomValidator in each row. The CustomValidator fires a function that compares all TextBoxes for equality. The algorithm for comparison is straightforward: *PSEUDOCODE*
3
1948
by: Lyners | last post by:
I have a table within a cell of a datagrid. I am doing updates without postback to the server using Javascript. I have everything working, except referencing a table within the datagrid cell. Here is my datagrid code for the cell; <asp:TemplateColumn HeaderText="3Fields" ItemStyle-Font-Size="8" SortExpression="Field1 ASC" ItemStyle-Font-Name="Verdana"> <ItemTemplate> <table border="0"> <tr>
21
5100
by: cmd | last post by:
I have code in the OnExit event of a control on a subform. The code works properly in this instance. If, however, I put the same code in the OnExit event of a control on a Tab Control of a main form, the code errors out at the 2nd line. The error number is 13 and the description is "Type mismatch". Both controls are memo fields. I suspect that "Screen.ActiveControl.Parent" is not referencing the form as intended. Thanks for any help,...
1
1390
by: msch-prv | last post by:
Sorry to bother. This is somewhat related to a post I made today. But I am really stuck! Is it possible to directly reference a control within a form view? For example, is it possible to assign the text attribute of a control using a control that is databound to a db? Or, must that be done via a specific script? I created an script using a FindControl("lbl1"), Label) to update label controls after the form is submitted. What I would...
5
6760
by: Amoril | last post by:
I've read quite a few different message on various boards and for some reason I'm still having trouble wrapping my head around this viewstate maintenance and trying to get these dynamically created link buttons to stay wired up to their click events. I have what is basically a simply survey question generation page. The page first displays a few static fields and a dropdownlist of various options for the user to select. When the user...
1
2449
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are of different lengths (e.g. usually between 25 and 45 rows. The columns in each file have the same length). The text files have been numbered sequentially e.g. cb0, cb1, cb2 and so on. I would like to read the data from each text file into...
4
1847
by: lindabaldwin | last post by:
Hello all, I am fairly new to VBA and have had limited work with checkboxes before. I have turned an Excel worksheet into a form in which users can enter data and click checkboxes. I want to record the data, including the data within the checkboxes, onto another worksheet. I am having a lot of trouble referencing, much less reading the checkboxes. I had used the format control to reference a cell, but this is not what I want. I need...
2
1481
by: =?Utf-8?B?SmFtZXMgUGFnZQ==?= | last post by:
Hi all I have a user control - mycontrol.ascx with various controls within it. mycontrol.ascx is utilised in myPage.aspx I have a class (class1) to carry out various functions, subs etc. How do I go about setting the properties of the controls within mycontrol.ascx directly from class1 Ideally what i'd like to do is various control property settings in class1
5
13378
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
9541
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
9370
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...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8242
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6074
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
4602
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
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
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
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.