protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        string id      = GridViewStudent.DataKeys[e.RowIndex].Value.ToString();
        bool   success = dao.DeleteBody(id, 1);

        if (success)
        {
            Response.Write("<script>alert('删除成功!')</script>");

            //刷新该页面
            SqlConnection  sqlConnection  = SqlTools.Connection();
            SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from student", sqlConnection);
            DataSet        dataSet        = new DataSet();
            GridViewStudent.DataKeyNames = new string[] { "id" };
            sqlDataAdapter.Fill(dataSet);
            GridViewStudent.DataSource = dataSet;
            GridViewStudent.DataBind();


            sqlConnection.Close();
        }
        else
        {
            Response.Write("<script>alert('删除失败!')</script>");
        }
    }
示例#2
0
 private void BindGridView()
 {
     try
     {
         if (conn.State == ConnectionState.Closed)
         {
             conn.Open();
         }
         MySqlCommand     cmd = new MySqlCommand("Select * from Student ORDER BY SID DESC;", conn);
         MySqlDataAdapter adp = new MySqlDataAdapter(cmd);
         DataSet          ds  = new DataSet();
         adp.Fill(ds);
         GridViewStudent.DataSource = ds;
         GridViewStudent.DataBind();
         lbltotalcount.Text = GridViewStudent.Rows.Count.ToString();
     }
     catch (MySqlException ex)
     {
         ShowMessage(ex.Message);
     }
     finally
     {
         if (conn.State == ConnectionState.Open)
         {
             conn.Close();
         }
     }
 }
        protected void Button2_Click(object sender, EventArgs e)
        {
            SqlCommand command = new SqlCommand("select count(*) from Student_Details where  RegistrationNo ='" + TextBoxRegNo.Text + "'", con);

            con.Open();
            int StudentExist = (int)command.ExecuteScalar();

            if (StudentExist > 0)
            {
                SqlCommand comd       = new SqlCommand("select count(*) from Allocation where  RegistrationNo ='" + TextBoxRegNo.Text + "' and Status='Active'", con);
                int        StudtExist = (int)comd.ExecuteScalar();
                if (StudtExist > 0)
                {
                    Labelwrite1.Text = "Student Already Alloted";
                }
                else
                {
                    SqlCommand    comnd = new SqlCommand("select RegistrationNo,Name,Gender from Student_Details where RegistrationNo ='" + TextBoxRegNo.Text + "'and  RegistrationNo  not in (select RegistrationNo from Allocation where Status= 'active')", con);
                    SqlDataReader rdr   = comnd.ExecuteReader();
                    GridViewStudent.DataSource = rdr;
                    GridViewStudent.DataBind();
                    con.Close();
                }
            }

            else
            {
                Labelwrite1.Text = "No Details Found Check If Regiatration No is correct";
            }
        }
示例#4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection();

            con.ConnectionString = WebConfigurationManager.ConnectionStrings["ConTest"].ConnectionString;
            try
            {
                using (con)
                {
                    string     command = "Select * from student";
                    SqlCommand cmd     = new SqlCommand(command, con);
                    con.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();

                    if (rdr.HasRows)
                    {
                        GridViewStudent.DataSource = rdr;
                        GridViewStudent.DataBind();
                    }
                    else
                    {
                        lblInfo.Text = "no record found";
                    }
                }
            }
            catch (Exception err)
            {
                lblInfo.Text  = "Error reading the datastore: ";
                lblInfo.Text += err.Message;
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            con.Open();
            SqlCommand    cmd = new SqlCommand("select RegistrationNo,Name,Gender from Student_Details where   Batch='" + DropDownListBatch.Text + "'and Branch='" + DropDownListBranch.Text + "' and  RegistrationNo  not in (select RegistrationNo from Allocation where Status= 'active')", con);
            SqlDataReader rdr = cmd.ExecuteReader();

            GridViewStudent.DataSource = rdr;
            GridViewStudent.DataBind();
            con.Close();
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection  sqlConnection  = SqlTools.Connection();
        SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("select * from student", sqlConnection);
        DataSet        dataSet        = new DataSet();

        GridViewStudent.DataKeyNames = new string[] { "id" };
        sqlDataAdapter.Fill(dataSet);
        GridViewStudent.DataSource = dataSet;
        GridViewStudent.DataBind();

        sqlConnection.Close();
    }
示例#7
0
        public void BindGridview()
        {
            try
            {
                SqlCommand     cmd = new SqlCommand("Select * from Students", conn);
                SqlDataAdapter adp = new SqlDataAdapter(cmd);
                conn.Open();
                DataSet ds = new DataSet();
                adp.Fill(ds);
                GridViewStudent.DataSource = ds;
                GridViewStudent.DataBind();
                conn.Close();
            }

            catch (Exception ex)
            {
            }
            finally
            {
            }
        }
示例#8
0
 protected void Page_Load(object sender, EventArgs e)
 {
     GridViewStudent.DataSource = LogicLayer.Student.GetAllStudents();
     GridViewStudent.DataBind();
 }