473,394 Members | 1,702 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,394 software developers and data experts.

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.Length-1 )
for j=i+1 thru ( Container.Length-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.Controls(i).UniqueID
aObjFirst(0) = CType( Me.FindControl(ControlName & "First"), TextBox
)
ControlName = OurDataGrid.Controls(j).UniqueID
aObjFirst(1) = CType( Me.FindControl(ControlName & "First"), TextBox
)

' If first names match...
If ( aObjFirst(0).Text=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 1650
--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.Controls.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.Length-1 )
for j=i+1 thru ( Container.Length-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.Controls(i).UniqueID
aObjFirst(0) = CType(Me.FindControl(ControlName & "First"), TextBox)
ControlName = OurDataGrid.Controls(j).UniqueID
aObjFirst(1) = CType(Me.FindControl(ControlName & "First"), TextBox)

' If first names match...
If ( aObjFirst(0).Text=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.Controls.Count-1 )
' get the control in row i with the same ID as the
sender
objFirst =
OurDataGrid.Items(i).FindControl(sender.ControlToV alidate)

If ( objFirst.Text=sender.Text )
value.IsValid = True
End If
Next
End Sub
I /think/ my only problem is the "SENDER_INDEX"--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 CustomValidators 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 valCustomControl As New CustomValidator
valCustomControl = sender
'Find the Parent Cell of Validation Control
Dim cell As TableCell = valCustomControl.Parent
'Find the Datagrid Item
Dim dgItem As DataGridItem = cell.Parent
'Set the Row
Dim myRow As DataRow =
DataSet.Tables("YourTableName").Rows(dgItem.ItemIn dex)

Nov 19 '05 #4

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

Similar topics

2
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...
0
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...
3
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. ...
21
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...
1
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...
5
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...
1
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...
4
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...
2
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...
5
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...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
0
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...
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.