COUNTASPX.CS

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class count : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(DataBase.connect);
        DataSet ds = new DataSet();
        string sql = "select Hostel from Stud_Info where Hostel = 'Charlie' ";
        try
        {
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
            adapter.Fill(ds);
            Label3.Text = " Strength " + ds.Tables[0].Rows.Count.ToString();
            con.Close();
        }
        catch (Exception ex)
        {
            Label3.Text = "Error in execution " + ex.ToString();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(DataBase.connect);
        DataSet ds = new DataSet();
        string sql = "select Hostel from Stud_Info where Hostel = 'Alpha' ";
        try
        {
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
            adapter.Fill(ds);
            Label1.Text = " Strength " + ds.Tables[0].Rows.Count.ToString();
            con.Close();
        }
        catch (Exception ex)
        {
            Label1.Text = "Error in execution " + ex.ToString();
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(DataBase.connect);
        DataSet ds = new DataSet();
        string sql = "select Hostel from Stud_Info where Hostel = 'Bravo' ";
        try
        {
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
            adapter.Fill(ds);
            Label2.Text = " Strength " + ds.Tables[0].Rows.Count.ToString();
            con.Close();
        }
        catch (Exception ex)
        {
            Label2.Text = "Error in execution " + ex.ToString();
        }
    }
    protected void Button4_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(DataBase.connect);
        DataSet ds = new DataSet();
        string sql = "select Hostel from Stud_Info where Hostel = 'Delta' ";
        try
        {
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
            adapter.Fill(ds);
            Label4.Text = " Strength " + ds.Tables[0].Rows.Count.ToString();
            con.Close();
        }
        catch (Exception ex)
        {
            Label4.Text = "Error in execution " + ex.ToString();
        }
    }
    protected void Button5_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(DataBase.connect);
        DataSet ds = new DataSet();
        string sql = "select Hostel from Stud_Info  ";
        try
        {
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(sql, con);
            adapter.Fill(ds);
            Label5.Text = " Total Strength " + ds.Tables[0].Rows.Count.ToString();
            con.Close();
        }
        catch (Exception ex)
        {
            Label5.Text = "Error in execution " + ex.ToString();
        }
    }
}





this will count the total number strength of dropdownlist as well as individual strength of 4 different element of dropdonlist
  1 ALPHA
2  BRAVO
3  CHARLIE
 4  DELTA 

0 comments:

Post a Comment