.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Imran Ghani
Sohaib Khalid

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Radiobuttonlist display.

Posted By: Shanthini     Posted Date: June 21, 2009    Points:2   Category :ASP.Net
I want the following items to be displayed in RadioButtonlist...
1. Overall
2. 'A' Grade
3. 'B' Grade
4. 'C' Grade.

The A,B,C Grade will come from a table if we take distinct value..
The 'overall' will not be in the table. I have used the following code for displaying, A, B, C.

Aspx code:

<asp:RadioButtonList ID="rbnList" runat="server" AutoPostBack="True" DataTextField="Topics"
DataValueField="Topics" OnSelectedIndexChanged="rbnList_SelectedIndexChanged" BackColor="Silver" BorderColor="Black" CellSpacing="10" ForeColor="Maroon" RepeatDirection="Horizontal" >

Aspx.cs code:

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlconnectionstring"].ConnectionString);
SqlCommand command = new SqlCommand("dbo.for_radio_display", conn);
command.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds, "dbo.for_radio_display");
rbnList.DataSource = ds;

The A,B,C are getting displayed properly.

Please provide me the idea for How to add "Overall" in the radiobuttonlist???
(How to add a Static item to item coming from database in radiobuttonlist)

Author: Praveen             
Posted Date: June 21, 2009     Points: 5   

You can user Items.Insert method to add item eg

rbnList.Items.Insert(0, new ListItem("Overall", "Overall"));

Use the above code after

rbnList.Items.Insert(0, new ListItem("Overall", "Overall"));

Happy Coding!!!

Author: Shanthini             
Posted Date: June 21, 2009     Points: 5   

Hi praveen,

Its working fine... Thank u :-)

I also got an idea for this, instead of using databind()... I have tried out the following,

foreach (DataRow dr in ds.Tables[0].Rows)

Its also working fine.. But your's sugestion is so simple and i am going to use that only... Thank u once agin :-)

Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend