Convert this VB code?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm a C# beginner. Can someone convert this VB code to C#?

Dim i as Integer
for i = 0 to 4
dim pnl as Panel = ctype(FindControl("pnl" & i.tostring), Panel)
if mytabstrip.SelectedIndex = i then
pnl.Visible="True"
else
pnl.Visible="False"
End If
next
End Sub

Thanks in advance.
 
pj,

Here you go.

// A loop variable.
int i;

// Cycle.
for i = 0 to 4
// Create a panel.
FindControl(string.Format("pnl{0}", i)).Visible =
(mytabstrip.SelectedIndex == i);

Hope this helps.
 
For (int I = 0; I <= 4; i++) {
Panel aPanel = this.FindControl("pnl" + i.ToString()) as Panel;
if (aPanel != null) {
// One way
if (myTabStrip.SelectedIndex == i) {
aPanel.Visible = true;
} else {
aPanel.Visible = false;
}
// Another way
aPanel.Visible = (myTabStrip.SelectedIndex == i);
}
}

HTH

Simon Smith
simon dot s at ghytred dot com
http://www.ghytred.com/NewsLook - Usenet for Outlook
 
for(int i = 0; i <= 4; i++)
{
Panel pnl = (Panel) FindControl("pnl" + i.ToString());
if(mytabstrip.SelectedIndex == i)
pnl.Visible = true;
else
pnl.Visible = false;
}

You can set all panels.Visible to false in a routine called by Page_Load,
then you end up with this idea:

//Not sure if event name is correct, so create event by double clicking tab
strip
private void myTabStrip_SelectedIndexChanged(object sender, EventArgs e)
{
//Look ma, no loop
Panel pnl = (Panel) FindControl("pnl" +
mytabstrip.SelectedIndex.ToString());
pnl.Visible = true;
}

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
 
If you want yet another angle, I used the Instant C# VB.NET to C#
converter to produce the following (after changing "True" to True and
"False" to False - not sure why you'd have these in quotes...):

int i;
for (i = 0; i <= 4; i++)
{
Panel pnl = ((Panel)(FindControl("pnl" + i.ToString())));
if (mytabstrip.SelectedIndex == i)
{
pnl.Visible=true;
}
else
{
pnl.Visible=false;
}
}
}
 
Back
Top