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: Vanaja Chiluveru 28 Nov 2008 | Member Level: Silver | Rating:  Points: 4 |
the following code will default the first radio button in the RowSelectorColumn collection to "checked" on initial page load.
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { RowSelectorColumn rsc = RowSelectorColumn.FindColumn(dgdReportTypes); int[] intSelIndex; intSelIndex = new int[1] { 0 }; rsc.SelectedIndexes = intSelIndex; } }
|