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 :)