I am creating a web based application (Student Registration Form). In this Web Page I have 1 dropdown list (which shows the lecturetimings like Saturday, Sunday, Monday, Tuesday,........etc). After selecting a list item(ex: Saturday It will show availble courses as Radio buttons (Example:MS-Office,C#.Net). In the selected index change event of drop down list-I have written a switch case: for every different case.
case 0: r1.Visible = false; r2.Visible = false; break;
case 1: r1.Visible = false; r2.Visible = false; r1.Text = "MS-Office"; r1.Visible = true; break;
case 2: r1.Visible = false; r2.Visible = false; r1.Text = "Hardware & Networking"; r2.Text="C#.net"; r1.Visible = true; r2.Visible = true; break;
...........
Upto case7 written.
Then I have some text boxes for (StudentName, EmailId, ContactNo.& address).
There is a submit button( on clicking this, the information wil be saved in data base table "registration"(StudentName,EmailId,ContactNo.,Address, Lecturetimings, Course)
Ex:(John, john@john.com, 9999999999, India, Saturday,MS-Office).
Now My requirement is if there 10 records with Saturday then in the dropdown list saturday should not be shown.
I solved this problem with help of a stored procedure.I have taken a data table and I inserted the values of "Lecturetimings" are less than 10 records. When I display the list items from the data table, it is working fine, it is showing only that items which are less than 10 records.
But the problem is it should initially all the list items,If there is no records in the database. And another problem is, when I select any list item then it should show the appropriate radio buttons(Initially it was showing, but after getting the data from the data table it is not working).
Thanks in advance for taking pains for me.
My Tried code so far is :
References: d1=dropdownlist1
r1=radiobutton1
r2=radiobutton2
Code:
protected void Page_Load(object sender, EventArgs e)
{
DataTable records = new DataTable();
string myConnection = "Data Source=server;Initial Catalog=college;User ID=sa;Password=123";
SqlConnection con = new SqlConnection(myConnection);
con.Open();
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.CommandText = "GetListRecordNotHavingTenCount";
sqlCommand.Connection = con;
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand); sqlDataAdapter.Fill(records);
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (d1.SelectedIndex)
{
case 0:
r1.Visible = false;
r2.Visible = false;
break;
case 1:
r1.Visible = false;
r2.Visible = false;
r1.Text = "C Language";
r2.Text = "C ++";
r1.Visible = true;
r2.Visible = true;
break;
case 2:
r1.Visible = false;
r2.Visible = false;
r1.Text = "Basic Hardware";
r1.Visible = true;
break;
case 3:
r1.Visible = false;
r2.Visible = false;
r1.Text = "Networking";
r1.Visible = true;
break;
case 4:
r1.Visible = false;
r2.Visible = false;
r1.Text = "Adobe Flash";
r2.Text = "Adobe Photoshop";
r1.Visible = true;
r2.Visible = true;
break;
case 5:
r1.Visible = false;
r2.Visible = false;
r1.Text = "C#.Net";
r1.Visible = true;
break;
case 6:
r1.Visible = false;
r2.Visible = false;
r1.Text = "Basic Hardware";
r1.Visible = true;
break;
case 7:
r1.Text = "Adobe Flash";
r2.Text = "Networking";
r1.Visible = true;
r2.Visible = true;
break;
}
}
protected void Button1_Click1(object sender, EventArgs e)
{
String myConnection = " Data Source=server;Initial Catalog=college;User ID=sa;Password=123";
SqlConnection con = new SqlConnection(myConnection);
SqlCommand cmd;
con.Open();
cmd = new SqlCommand(@"INSERT INTO [dbo].[Register]([Sname],[Email]
,[ContactNo],[Activity],[Lecturetimings])
VALUES('" + name.Text + "','" + email.Text + "','" + contact.Text + "','" + r1.Text + "','"+d1.SelectedValue+"')", con);
cmd.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterStartupScript(this, GetType(), "alert", "alert('SuccessFully Submitted');", true);
d1.SelectedIndex = 0;
name.Text = "";
email.Text = "";
contact.Text = "";
CheckBox1.Checked = false;
r1.Visible = false;
r2.Visible = false;
}