在C#中单击按钮时,在另一个复选框上指定复选框状态

时间:2014-08-07 16:36:21

标签: c# checkbox

我想要做的是点击一个按钮后复制checkbox的现有状态:

protected void MROSelector_SelectedIndexChanged(object sender, EventArgs e)
{
    //Checkbox checking for MRO/MRO50k
    if (MROSelector.SelectedIndex == 0)
    {
        acdMroProj.Visible = true;
        acdMroProj_50k.Visible = false;
        acdMroProj_50k.Enabled = false;
        acdMroProj.Enabled = true; 
    }
    else
    {
        acdMroProj.Visible = false;
        acdMroProj_50k.Visible = true;
        acdMroProj.Enabled = false;
        acdMroProj_50k.Enabled = true;
    }            
}

这是我的checkboxes

的代码
public partial class MRO50k : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    { }

    private string GetCheckedCBL()
    {
        string str = "";
        bool b = (CheckBoxList1.Items[0].Selected ^ CheckBoxList1.Items[1].Selected);
        if (b)
        {
            if (CheckBoxList1.Items[0].Selected) { str = CheckBoxList1.Items[0].Value; }
            if (CheckBoxList1.Items[1].Selected) { str = CheckBoxList1.Items[1].Value; }
        }
        return str;
    }

    public string GetSelectedMROProjFilter { get { return GetCheckedCBL(); } }
}

public partial class MROProj : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    { }

    private string GetCheckboxListSelection()
    {
        string str = "";
        bool b = (CheckBoxList1.Items[0].Selected ^ CheckBoxList1.Items[1].Selected);
        if (b)
        {
            if (CheckBoxList1.Items[0].Selected) { str = CheckBoxList1.Items[0].Value; }
            if (CheckBoxList1.Items[1].Selected) { str = CheckBoxList1.Items[1].Value; }
        }
        return str;
    }

    public string GetStrSelection { get { return GetCheckboxListSelection(); } }  
}

0 个答案:

没有答案