正文

供求信息網(wǎng)(24)

ASP.NET項目開發(fā)案例全程實錄(第2版) 作者:明日科技


SelectedIndexChanging事件發(fā)生在單擊某一行的“審核/取消”按鈕以后發(fā)生,本程序通過該事件實現(xiàn)對供求信息的審核和取消工作。實現(xiàn)代碼如下:

例程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);

//按審核類型綁定數(shù)據(jù)(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事件是在單擊某一行的“詳細(xì)信息”按鈕時,但在GridView控件刪除該行之前發(fā)生。在此不是實現(xiàn)刪除,只是通過刪除命令完成查看詳細(xì)供求信息的功能。實現(xiàn)代碼如下:

例程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事件是在單擊某一頁導(dǎo)航按鈕時,但在GridView控件處理分頁操作之前發(fā)生。通過該事件主要實現(xiàn)頁面的分頁功能。另外,本程序主要實現(xiàn)了按審核、未審核等情況顯示供求信息,需要按相應(yīng)情況的數(shù)據(jù)源綁定GridView控件,否則程序不會報錯,但會出現(xiàn)亂分頁現(xiàn)象。實現(xiàn)代碼如下:

例程33 代碼位置:光盤\TM\01\SIS\ BackGround\ CheckInfo.aspx.cs

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

{

//分頁設(shè)置

GridView1.PageIndex = e.NewPageIndex;

//按審核類型綁定數(shù)據(jù)(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;

}

//顯示當(dāng)前頁數(shù)

lblPageSum.Text = "當(dāng)前頁為 " + (GridView1.PageIndex + 1) + " / " + GridView1.PageCount + " 頁";

}

單擊“已經(jīng)審核供求信息”按鈕,顯示已經(jīng)審核的供求信息。實現(xiàn)代碼如下:

例程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;

//顯示當(dāng)前頁數(shù)

lblPageSum.Text = "當(dāng)前頁為 " + (GridView1.PageIndex + 1) + " / " + GridView1.PageCount + " 頁";

}

單擊“未審核供求信息”按鈕,顯示未審核的供求信息。實現(xiàn)代碼如下:

例程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;

//顯示當(dāng)前頁數(shù)

lblPageSum.Text = "當(dāng)前頁為 " + (GridView1.PageIndex + 1) + " / " + GridView1.PageCount + " 頁";

}

單擊“顯示同類型所有供求信息”按鈕,顯示同類型所有供求信息。實現(xiàn)代碼如下:

例程36 代碼位置:光盤\TM\01\SIS\ BackGround\ CheckInfo.aspx.cs

protected void rdoBtnCheckAll_CheckedChanged(object sender, EventArgs e)

{

GridView1.PageIndex = 0;

GridViewBind(infoType);

CheckType = -1;

//顯示當(dāng)前頁數(shù)

lblPageSum.Text = "當(dāng)前頁為 " + (GridView1.PageIndex + 1) + " / " + GridView1.PageCount + " 頁";

}


上一章目錄下一章

Copyright ? 讀書網(wǎng) ranfinancial.com 2005-2020, All Rights Reserved.
鄂ICP備15019699號 鄂公網(wǎng)安備 42010302001612號