Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 1st, 2009, 02:41 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default Finding Control

Hi,

I'm trying to show/hide controls depending on DB results. I can find the labels and set the value but I have no idea how to find the HTMLTableRow and set the Visible attribute so that I can show/hide that row.

For Each oDR In oDS.Tables(0).Rows
Dim lblVal As Label = Page.FindControl("lbl" & oDR("TankDefName"))
lblVal.Text = oDR("TankDataDesc")
Dim tdrVisible As HtmlTableRow = Page.FindControl("tr" & oDR("TankDefName"))
Next

You're help is greatly apprecaited.

Thanks,
Richard
  #2 (permalink)  
Old September 5th, 2009, 06:43 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Richard,

Can you provide a bit more information? For example, where and how did you define the table row?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
  #3 (permalink)  
Old September 6th, 2009, 01:26 AM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Hi Imar,

Thanks for the reply. Very much appreciated.

This is what I have now that is working. I'm able to get and assign the values to the labels fine. Actually this is someone else's code on my team and I'm looking at this and I don't know why the variable, Dim lblval As Label, is defined within the loop. Does that make any difference?


Code:
Dim SQL As String = "SELECT TankDefID, TankDefName, TankDataDesc FROM TankDefinitions WHERE RuleID = " & _RuleID 
Dim oDA As New SqlDataAdapter(SQL, _oConn)
Dim oDS As New DataSet
Dim oDR As DataRow
oDA.Fill(oDS)

If oDS.Tables(0).Rows.Count > 0 Then
    For Each oDR In oDS.Tables(0).Rows
    Dim lblVal As Label = Page.FindControl("lbl" & oDR("TankDefName"))
    lblVal.Text = oDR("TankDataDesc")
Next

Oops.

In my previous code I had.

Code:
    Dim tdrVisible As HtmlTableRow = Page.FindControl("tr" & oDR("TankDefName"))
However, the id for the table tag is id=tdrTankBit1 and so forth and not trTankBit1. I don't know if that even is going to make any difference. The other developer has the page checked out now so I can't try that now.

I'll get the page, change the "tr" to "tdr" and get the exact line and error that it's generating.

If you have any ideas in the meant, they would be very much appreciated.

Thanks,
Richard
  #4 (permalink)  
Old September 6th, 2009, 06:44 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Richard,

Apparently, lblVal is used to dynamically find controls in the page. Normally, you would just us this:

lblVal.Text = "SomeText"

provided you have a Label like this in the code:

<asp:Label ID="lblVal" runat="server" />

However, the code is dynamically find the right labels based on the TankDefName from your database.

You can do the same trick with tables and rows (or any other HTML element), provided you give them an ID and runat attribute:

<tr id="SomeId" runat="server">

Then you can program against the SomeId row...

Hope this clarifies things a bit.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
rstelma (September 7th, 2009)
  #5 (permalink)  
Old September 7th, 2009, 03:20 AM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Hi Imar,

I'm such a ding dong. I was defining the table row id's as 'tdr' plus the value in the database.

Code:
<tr id="tdrSMint1" runat="server" />
All I had to do to make this work was to change "tr" to "tdr".

And that's probably why you asked to see the front page code.

Code:
Dim tdrVisible As HtmlTableRow = Page.FindControl("tr" &  oDR("TankDefName"))
To this:

Code:
Dim tdrVisible As HtmlTableRow = Page.FindControl("tdr" &  oDR("TankDefName"))
She worky. Like a dream.

Thanks so much for your reply. Extreme thanks.

Richard


Similar Threads
Thread Thread Starter Forum Replies Last Post
finding error capri C# 2 April 2nd, 2008 12:53 AM
Finding items in a dropdownlist control johnnycorpse Classic ASP Components 0 May 18th, 2007 04:09 AM
finding a worksheet ozPATT Excel VBA 4 November 16th, 2005 10:54 AM
finding control type sureshkamma20 Classic ASP Professional 5 June 16th, 2004 03:34 PM
Finding a matching value Morry Excel VBA 2 March 26th, 2004 05:32 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.