.NET C# how to loop through some lable to set their attribute

Posted by sydney wynn on Stack Overflow See other posts from Stack Overflow or by sydney wynn
Published on 2010-05-26T18:56:45Z Indexed on 2010/05/26 19:01 UTC
Read the original article Hit count: 325

Filed under:

How do I do this in a loop.

protected void ddlTool_SelectedIndexChanged(object sender, EventArgs e)
{

    lblTool1.Visible = false;
    txtTool1.Visible = false;
    lblTool2.Visible = false;
    txtTool2.Visible = false;
    lblTool3.Visible = false;
    txtTool3.Visible = false;
    lblTool4.Visible = false;
    txtTool4.Visible = false;
    lblTool5.Visible = false;


    if (ddlTool.SelectedValue == "1")
    {
        lblTool1.Visible = true;
        txtTool1.Visible = true;
    }
    if (ddlTool.SelectedValue == "2")
    {
        lblTool1.Visible = true;
        txtTool1.Visible = true;
        lblTool2.Visible = true;
        txtTool2.Visible = true;
    }
    if (ddlTool.SelectedValue == "3")
    {
        lblTool1.Visible = true;
        txtTool1.Visible = true;
        lblTool2.Visible = true;
        txtTool2.Visible = true;
        lblTool3.Visible = true;
        txtTool3.Visible = true;
    }
    if (ddlTool.SelectedValue == "4")
    {
        lblTool1.Visible = true;
        txtTool1.Visible = true;
        lblTool2.Visible = true;
        txtTool2.Visible = true;
        lblTool3.Visible = true;
        txtTool3.Visible = true;
        lblTool4.Visible = true;
        txtTool4.Visible = true;
    }

© Stack Overflow or respective owner

Related posts about c#