Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<asp:RadioButtonList ID="r1" runat="server" AutoPostBack="True" RepeatColumns="3" RepeatDirection="Horizontal">
    </asp:RadioButtonList>


What I have tried:

private void yrs()
     {
         DataSet sid = new DataSet();
         string aise = "select distinct yearr from programe where course='" + ddcorese.SelectedItem.Text.ToString() + "'";
         sid = mvl.GETDS(aise);
         ListItem liq = new ListItem();
         liq.Value = "--Select--";
         r1.Items.Add(liq.ToString());
         r1.DataSource = sid;
         r1.DataTextField = "yearr";
         r1.DataBind();               
     }
Posted
Updated 23-Jun-20 10:29am
Comments
F-ES Sitecore 23-Jun-20 6:16am    
Use the debugger to step through the code, does "sid" contain any data?

Also if you want to have both items you add and items that are databound you need to specify AppendDataBoundItems="true" either in the mark-up or the code behind. Also it is pointless adding a "--Select--" prompt to a radio button list.

1 solution

Please try these suggestions and see if that helps-

1. Make sure, you have called the yrs() method inside the Page_Load() event and wrapped inside the check for postback something like following-
C#
if(!Page.IsPostBack)
{
   yrs();
}


2. Change AutoPostBack="True" to AutoPostBack="False". This is because you are not using any event of the control that requires a PostBack.
3.
SQL
string aise = "select distinct yearr from programe where course='" + ddcorese.SelectedItem.Text.ToString() + "'";

The above code is vulnerable to SQL Injection and you must use a parameterized query or stored procedure instead of an inline query. Please the following article to know more about it-
SQL Injection Attack, its examples and Prevention mechanisms and Techniques in ASP.Net[^]
4.
SQL
string aise = "select distinct yearr from programe where course='" + ddcorese.SelectedItem.Text.ToString() + "'";

Instead of using SelectedItem.Text use SelectedValue. Note: The value field should have the desired data for this to work.
5. Make sure a value is selected in the ddcorese dropdown.
6. Use standard and error-free spelling of English words so that there will be less chance of typos.
7. Remove following 3 lines as these are irrevalent to checkboxlist
C#
ListItem liq = new ListItem();
 liq.Value = "--Select--";
 r1.Items.Add(liq.ToString());

8. Replace next 3 lines with following -

C#
r1.DataTextField = "yearr";
r1.DataValueField = "yearr";
r1.DataSource = sid;
r1.DataBind();



If the issue still persists, please let me know.

Hope, it helps :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900