Hi guys i have a Datagrid here that has radio buttons and it is populated by information from a database i got all that to work,but now what i want to do,i want to have a first record selected by default,so that means the radio button of the first record has to be checked by default when the page loads.below is the code on the radiobutton check changed event:
RadioButton oRb1 = (RadioButton)sender;
foreach (DataGridItem oItem in DataGrid4a.Items) { //Find the previous selected radio button RadioButton oRb2 = (RadioButton)oItem.FindControl("rb4a");
//Display info if (oRb2.Equals(oRb1)) { Message.Text = String.Format("Selected Id is: {0}, and the Description is: {1}", ((Label)oItem.FindControl("lblId")).Text, ((Label)oItem.FindControl("lblDesc")).Text); //((Label)oItem.FindControl("lblId")).Text, ((Label)oItem.FindControl("lblDesco")).Text, ((Label)oItem.FindControl("lblSemester")).Text);
lblCos.Text = ((Label)oItem.FindControl("lblId")).Text; lblMos.Text = ((Label)oItem.FindControl("lblDesco")).Text; lblSes.Text = ((Label)oItem.FindControl("lblSemester")).Text; lblType.Text = ((Label)oItem.FindControl("lblOfferingType")).Text;
} //Uncheck previously selected button else oRb2.Checked = false; }
|
| Author: Williams 21 Nov 2008 | Member Level: Gold | Rating:  Points: 3 |
try to get the radiobutton control in the item databound event and set the selected property of the radiobutton to true.Make sure you check that the rowcount is 1 which is the first record where as rowcount 0 is the header
|