SelectedIndexChanging事件发生在单击某一行的“审核/取消”按钮以后发生,本程序通过该事件实现对供求信息的审核和取消工作。实现代码如下:
例程31 代码位置:光盘\TM\01\SIS\ BackGround\ CheckInfo.aspx.cs
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
string id = GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
operation.UpdateInfo(id, infoType);
//按审核类型绑定数据(3种类别:全部显示(-1)、显示未审核(0)、显示审核(1))
switch (CheckType)
{
case -1:
GridViewBind(infoType);
break;
case 0:
GridView1.DataSource = operation.SelectInfo(infoType, false);
GridView1.DataBind();
break;
case 1:
GridView1.DataSource = operation.SelectInfo(infoType, true);
GridView1.DataBind();
break;
}
}
RowDeleting事件是在单击某一行的“详细信息”按钮时,但在GridView控件删除该行之前发生。在此不是实现删除,只是通过删除命令完成查看详细供求信息的功能。实现代码如下:
例程32 代码位置:光盘\TM\01\SIS\ BackGround\ CheckInfo.aspx.cs
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
Response.Write("<script> window.open('DetailInfo.aspx?id=" + id + "&&type=" + infoType + "','','height=258, width=679, top=200, left=200') </script>");
Response.Write("<script>history.go(-1)</script>");
}
PageIndexChanging事件是在单击某一页导航按钮时,但在GridView控件处理分页操作之前发生。通过该事件主要实现页面的分页功能。另外,本程序主要实现了按审核、未审核等情况显示供求信息,需要按相应情况的数据源绑定GridView控件,否则程序不会报错,但会出现乱分页现象。实现代码如下:
例程33 代码位置:光盘\TM\01\SIS\ BackGround\ CheckInfo.aspx.cs
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//分页设置
GridView1.PageIndex = e.NewPageIndex;
//按审核类型绑定数据(3种类别:全部显示(-1)、显示未审核(0)、显示审核(1))
switch (CheckType)
{
case -1:
GridViewBind(infoType);
break;
case 0:
GridView1.DataSource = operation.SelectInfo(infoType, false);
GridView1.DataBind();
break;
case 1:
GridView1.DataSource = operation.SelectInfo(infoType, true);
GridView1.DataBind();
break;
}
//显示当前页数
lblPageSum.Text = "当前页为 " + (GridView1.PageIndex + 1) + " / " + GridView1.PageCount + " 页";
}
单击“已经审核供求信息”按钮,显示已经审核的供求信息。实现代码如下:
例程34 代码位置:光盘\TM\01\SIS\ BackGround\ CheckInfo.aspx.cs
protected void rdoBtnCheckTrue_CheckedChanged(object sender, EventArgs e)
{
GridView1.PageIndex = 0;
GridView1.DataSource = operation.SelectInfo(infoType, true);
GridView1.DataBind();
CheckType = 1;
//显示当前页数
lblPageSum.Text = "当前页为 " + (GridView1.PageIndex + 1) + " / " + GridView1.PageCount + " 页";
}
单击“未审核供求信息”按钮,显示未审核的供求信息。实现代码如下:
例程35 代码位置:光盘\TM\01\SIS\ BackGround\ CheckInfo.aspx.cs
protected void rdoBtnCheckFalse_CheckedChanged(object sender, EventArgs e)
{
GridView1.PageIndex = 0;
GridView1.DataSource = operation.SelectInfo(infoType, false);
GridView1.DataBind();
CheckType = 0;
//显示当前页数
lblPageSum.Text = "当前页为 " + (GridView1.PageIndex + 1) + " / " + GridView1.PageCount + " 页";
}
单击“显示同类型所有供求信息”按钮,显示同类型所有供求信息。实现代码如下:
例程36 代码位置:光盘\TM\01\SIS\ BackGround\ CheckInfo.aspx.cs
protected void rdoBtnCheckAll_CheckedChanged(object sender, EventArgs e)
{
GridView1.PageIndex = 0;
GridViewBind(infoType);
CheckType = -1;
//显示当前页数
lblPageSum.Text = "当前页为 " + (GridView1.PageIndex + 1) + " / " + GridView1.PageCount + " 页";
}