Click here to Skip to main content
14,576,808 members
Rate this:
Please Sign up or sign in to 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

Rate this:
Please Sign up or sign in to vote.

Solution 1

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-
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.
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.
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
ListItem liq = new ListItem();
 liq.Value = "--Select--";
 r1.Items.Add(liq.ToString());

8. Replace next 3 lines with following -

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



If the issue still persists, please let me know.

Hope, it helps :)
   
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month



CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100