View Single Post
  #6 (permalink)  
Old August 18th, 2010, 12:32 AM
chroniclemaster1 chroniclemaster1 is offline
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Quote:
Originally Posted by daccit View Post
Hi Steve,

: public void CheckedBox1l_CheckedChanged(object sender, EventArgs e)
{
CheckBox Mychk = (CheckBox)sender;
Panel MyPanel = (Panel)FormView1.FindControl("Panel2");
MyPanel.Visible = Mychk.Checked;
}

try this;
It's easier to convert code in a language you're not comfortable with into your own language because that way the final product at least makes sense because you know the syntax. Therefore, I'd recommend that you translate it into VB yourself, since daccit and I are primarily C# guys. You don't want to see how many compilers our VB suggestions would throw. :) You are simply creating an event handler for a particular checkbox, CheckedBox1, when it's state is changed (it's checked or unchecked). Here's what's going on in this example, this is the code you're trying to recreate in VB.

First you create a new checkbox control in code, Mychk, and load the checkbox which has changed (the sender) into it. This is why you are casting the sender, so that it is the correct type when you store it in Mychk. You then repeat this process with the panel. You create a new panel in code, MyPanel. Using the FindControl() method you retrieve the panel with id="Panel2" that's inside FormView1, not that again you have to cast it to the correct type (Panel) in order to assign it to MyPanel (just like you had to for Mychk).

The third step is actually two steps combined. You are setting the visible property of MyPanel to true (which makes it visible) or false. However, you don't see any booleans, because the code directly assigns the Checked value (which is either true or false) from the Mychk checkbox. So if someone checks the checkbox, it's state changes and this function fires. The value of the checkbox is now checked and so this statement is true; line three assigns this "true" value to the visible property of the panel and the panel therefore appears. Now if someone unchecks the box, it's status changes and this function fires again. Now it's not checked so the Checked value is "false" and when that's assigned to MyPanel.Visible, the panel disappears. I hope that's clear?
__________________
-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
Reply With Quote