How to implement this function of all dataviewers in ASP.NET C#?
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.
精彩评论