📄 stuinfoview.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Web.SessionState;
public partial class stuInfoView : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(Session["adminId"]==null)
{
Response.Redirect("Default.aspx");
}else{
if(!IsPostBack)
{
BindGrid();
}
}
}
private void BindGrid()
{
DataSet ds=new DataSet();
ds=(new projClass()).getStuInfo();
DataTable dt=ds.Tables["stuInfo"];
DataView dv=new DataView(dt);
if(DropDownList1.SelectedItem.Value=="stuStatus")
dv.RowFilter="stuStatus like '%"+DropDownList2.SelectedItem.Text+"%'";
else dv.RowFilter=""+DropDownList1.SelectedItem.Value.ToString()+" like '%"+tbx_query.Text.Trim()+"%'";
this.GridView1.DataSource = dv;
if(dv.Count==0)
{
lbl_noResult.Visible=true;
this.GridView1.Visible=false;
}
else
{
lbl_noResult.Visible=false;
this.GridView1.Visible = true;
}
this.GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGrid();
}
protected void cbSel_CheckedChanged(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox cbSel = (CheckBox)gvr.Cells[0].FindControl("cbSel");
if (cbSel.Checked == false)
{
//选择一项后要干什么
}
}
}
protected void cbSelAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox cbAll = (CheckBox)sender;
if (cbAll.Text == "全选")
{
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox cbSel = (CheckBox)gvr.Cells[0].FindControl("cbSel");
cbSel.Checked = cbAll.Checked;
}
}
}
public string getFirstSelected()
{
bool selected=false;//判断用户是否选择了一个记录
string selectedId="";
foreach (GridViewRow gvr in GridView1.Rows)
{
if(!selected)
{
CheckBox cbx=(CheckBox)gvr.Cells[0].FindControl("cbSel");;
if(cbx!=null)
{
if(cbx.Checked)
{
selectedId = gvr.Cells[1].Text;
selected=true;
return selectedId;
}
}
}
}
if(!selected)
{
selectedId="none";
}
return selectedId;
}
protected void Ibtn_query_Click(object sender, ImageClickEventArgs e)
{
ViewState.Clear();
this.GridView1.PageIndex = 0;
BindGrid();
// this.UpdatePanel1.Update();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedItem.ToString() == "学生状态")
DropDownList2.Visible = true;
else DropDownList2.Visible = false;
}
//新增事件
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Response.Write("<script>window.open('addStu.aspx','添加学生记录','height=285,width=450,top=100,left=300,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no')</script>");
}
//修改事件
protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
{
string stuId = getFirstSelected();
if (!(stuId == "none"))
{
Session["stuId"] = stuId;
Response.Write("<script>window.open('studentUpdate.aspx','修改学生记录','height=285,width=450,top=100,left=300,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no')</script>");
}
else Response.Write("<script>alert(\"请选择一个学生!\");</script>");//没有选择记录
}
//删除事件
protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
{
string stuId = getFirstSelected();
if (!(stuId == "none"))
{
//Hashtable ht_stuId;
//if (Session["ht_stuId"] != null)
//{
// //Hashtable
// ht_stuId = (Hashtable)Session["ht_stuId"];
//}
//else
//{
// // Hashtable
// ht_stuId = new Hashtable();
// Session["ht_stuId"] = ht_stuId;
//}
foreach (GridViewRow gvr in GridView1.Rows)
{
CheckBox cbx = (CheckBox)gvr.FindControl("cbSel");
if (cbx.Checked)
{
string id = gvr.Cells[1].Text.ToString().Trim();
string name = gvr.Cells[2].Text.ToString().Trim();
//if (!ht_stuId.Contains(id))
// ht_stuId.Add(id, name);
}
}
//Hashtable ht_stuId = (Hashtable)Session["ht_stuId"];
//IDictionaryEnumerator myEnumerator = ht_stuId.GetEnumerator();
//while (myEnumerator.MoveNext())
//{
int count;
count = (new projClass()).deleteStuInfo(stuId);
//}
// Response.Write("<script>window.open('studentDelete.aspx','删除学生记录','height=285,width=450,top=100,left=300,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no')</script>");
ScriptManager.RegisterStartupScript(UpdatePanel1, this.GetType(), "删除", "alert('删除成功')", true);
BindGrid();
}
else Response.Write("<script>alert('请选择一个学生!');</script>");//没有选择记录
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -