"Haha, read this article ?"
Insus. NET first of all, I would like to thank the netizens for their attention to the previous blog. To solve your problem, you can try to get the index or primary key of the selected row. You can get the primary key and the value of other fields.
In the highlighted selection area, that is, to solve the problem and add it in the original code. First, add a DataKeyField to the DataList control to obtain its primary key value. In addition, two buttons and a Label are added to display the selection result, in the future, you may not be able to use tags, because after obtaining the results, you can do what you want.
The two buttons are simple, and Insus. NET is believed to be understandable. If you encounter an unknown event, you can discuss:
Copy codeThe Code is as follows:
View Code
Protected void button#click (object sender, EventArgs e)
{
Button button = (Button) sender;
If (FindControl ("DataListConstellation") = null) return;
DataList dlconstellation = (DataList) FindControl ("DataListConstellation ");
Foreach (DataListItem dli in dlconstellation. Items)
{
If (dli. FindControl ("RadioButtonSelect") = null) return;
RadioButton rb = (RadioButton) dli. FindControl ("RadioButtonSelect ");
If (rb. Checked)
{
LabelSelectedResult. text = string. format ("You execute the button '{0}' and select the row index: {1}; primary key value: {2}", button. text, dli. itemIndex. toString (), dlconstellation. dataKeys [dli. itemIndex]. toString ());
Break;
}
Else
{
LabelSelectedResult. Text = string. Format ("You executed the button '{0}' and did not select any row. ", Button. Text );
}
}
}
Protected void Button2_Click (object sender, EventArgs e)
{
Button button = (Button) sender;
DataList dlconstellation = (DataList) FindControl ("DataListConstellation ");
For (int I = 0; I <dlconstellation. Items. Count; I ++)
{
RadioButton rb = (RadioButton) dlconstellation. Items [I]. FindControl ("RadioButtonSelect ");
If (rb. Checked)
{
LabelSelectedResult. text = string. format ("You execute the button '{0}' and select the row index: {1}; primary key value: {2}", button. text, I. toString (), dlconstellation. dataKeys [I]. toString ());
Break;
}
Else
{
LabelSelectedResult. Text = string. Format ("You executed the button '{0}' and did not select any row. ", Button. Text );
}
}
}