开发者

How to implement this function of all dataviewers in ASP.NET C#?

开发者 https://www.devze.com 2023-01-04 00:50 出处:网络
I am displaying four records at a time, each having a check box. The design is static. I would like to know a way to find out, if a check box clicked, then 开发者_开发问答extract the name displayed i

I am displaying four records at a time, each having a check box.

The design is static. I would like to know a way to find out, if a check box clicked, then 开发者_开发问答extract the name displayed in label to its left.

How would the code know what lies to its left?

That is, find out in which row the click occurred?


public partial class FancyControl : Canvas
{
    CheckBox myCheckBox;
    Label myLabel;

    public FancyControl() { }
    public FancyControl(CheckBox cb, Label l)
    {
        myCheckBox = cb;
        myLabel = l;
        Children.Add(myCheckBox);
        Children.Add(myLabel);
        //Formatting goes here
    }

    public string GetText()
    {
        return myLabel.Content.ToString();
    }

    public bool IsChecked()
    {
        return myCheckBox.IsChecked.Value;
    }
}

You will have to do the formatting on your own, but essentially with this you will create 4 "FancyControl"s and then with each one you can call the IsChecked() method and if true call the GetText() method.

To create a FancyControl it would look like

FancyControl fC = new FancyControl(checkBox1, label1);

You would then add fC to your window or wherever it is supposed to go.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号