在DataGrid控件标签中加入如下代码
OnPageIndexChanged="DataGrid1_PageIndexChanged"
在后台中加入如下代码
///<summary>
///响应分页事件
///</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
publicvoidDataGrid1_Page(Objectsender,DataGridPageChangedEventArgse)
{
DataGrid1.CurrentPageIndex=e.NewPageIndex;
DataBind();
}
9.为DataGrid控件添加绑定事件,即在DataGrid绑定时发生的事件处理
一般用些事件来,做一些页面上的效果.如更改背景色,文本框大小等.
OnItemDataBound="DataGrid1_ItemDataBound"
///<summary>
///响应DataGrid绑定事件
///</summary>
///<paramname="sender"></param>
///<paramname="e"></param>
publicvoidDataGrid1_ItemDataBound(objectsender,System.Web.UI.WebControls.DataGridItemEventArgse)
{
if(e.Item.ItemType==ListItemType.Item)
{
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor=’#c8dafa’");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=’white’");
}
elseif(e.Item.ItemType==ListItemType.AlternatingItem)
{
e.Item.Attributes.Add("onmouseover","this.style.backgroundColor=’#c8dafa’");
e.Item.Attributes.Add("onmouseout","this.style.backgroundColor=’#f6f6f6’");
}
}
10.为DataGrid控件添加接钮处理事件程序
在DataGrid控件标签中加入如下代码
OnItemCommand="ItemsGrid_Command"
在后台中加入如下代码
publicvoidItemsGrid_Command(Objectsender,DataGridCommandEventArgse)
{
switch(((LinkButton)e.CommandSource).CommandName)
{
case"Delete":
intclassID=Int32.Parse((e.Item.Cells[0].Text).ToString());
ActorClass.DeleteActorClass(classID);
if(Request.QueryString.Get("classID")!=null)
Common.BindData(DataGrid1,Common.GetSource("select*fromActorClasswhereparentID="+Request.QueryString.Get("classID")+"orderbydepth,orderIDdesc"));
本新闻共6页,当前在第1页 1 2 3 4 5 6
