C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » ASP.NET »

default selection on a datagrid that has radio buttons C#


Posted Date: 20 Nov 2008      Posted By: Spha      Member Level: Silver     Points: 1   Responses: 1



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;
}





Responses

Author: Williams    21 Nov 2008Member Level: GoldRating: 2 out of 52 out of 5     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


Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : having a first record selected by default on a Datagrid with Radiobuttons C#
Previous : Mr india
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use