p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Basics (http://p2p.wrox.com/forumdisplay.php?f=136)
-   -   Adding a Panel control in FormView (http://p2p.wrox.com/showthread.php?t=45188)

steve35719 July 13th, 2006 11:42 AM

Adding a Panel control in FormView
 
I'm trying to add a panel to an EditItemTemplate of a FromView without success. I have a checkbox with the checked property bound to a field in the FormView. I'm trying to react to the checkbox's checked state by making a panel visible if the checkbox is checked and invisible if it is not checked. Anyone with any suggestions? I'm not finding much in the way of documentation for this problem. Thanks. Greg.


oguchi August 6th, 2010 03:52 AM

Having same problems in FormView on InsertItem Template.
Any ideas will be welcome.
Imar suggested Googling FINDCONTROL. I took onelook, but it was almost overwhelming.
Let me know what you find!

daccit August 13th, 2010 06:06 AM

solution
 
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;

oguchi August 13th, 2010 08:20 AM

Thanks. Is this in VB or C? Could you post the VB version, please.
Oguchi

daccit August 14th, 2010 02:38 AM

Hi Oguchi,
Thanks for getting back to me.Actully this code is for c#. Becuse we are working on c# only.


Let me know if you have any more query.

Thanks

chroniclemaster1 August 18th, 2010 12:32 AM

Quote:

Originally Posted by daccit (Post 261720)
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?


All times are GMT -4. The time now is 01:00 PM.

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