GridView动态绑定数据、编辑、修改、删除及分页功能

None.gif   protected   void  Page_Load( object  sender, EventArgs e)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        
if (!Page.IsPostBack)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            deptDataBind();
ExpandedSubBlockEnd.gif        }

InBlock.gif     
ExpandedBlockEnd.gif    }

None.gif    
// 数据绑定到控件
ExpandedBlockStart.gifContractedBlock.gif
     protected   void  deptDataBind()  dot.gif {
InBlock.gif        
//这是一个动态绑定到控件的函数
ExpandedBlockEnd.gif
    }

None.gif    
// 点击编辑进入到编辑状态
None.gif
     public   void  dept_Edit(Object sender, GridViewEditEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        dept.EditIndex 
= (int)e.NewEditIndex;
InBlock.gif        deptDataBind();
ExpandedBlockEnd.gif    }

None.gif    
// 删除数据控件上一行
None.gif
     public   void  dept_Delete(Object sender, GridViewDeleteEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        Dept _dept 
= new Dept();
InBlock.gif        
int Dept_ID = Int32.Parse(((Label)dept.Rows[e.RowIndex].Cells[0].Controls[0]).Text);
InBlock.gif        
if (_dept.Del(Dept_ID) == 1)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write(
"<script>alert('删除成功!');</script>");
InBlock.gif
ExpandedSubBlockEnd.gif        }

InBlock.gif        
else
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Response.Write(
"<script>alert('删除失败!');</script>");
InBlock.gif
ExpandedSubBlockEnd.gif        }
 
InBlock.gif        deptDataBind();
ExpandedBlockEnd.gif    }

None.gif    
// 取消数据控件上编辑
None.gif
     public   void  dept_Cancel(Object sender, GridViewCancelEditEventArgs e) 
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        dept.EditIndex 
= -1;
InBlock.gif        deptDataBind();
ExpandedBlockEnd.gif    }

None.gif    
// 把数据控件上的数据更新到数据据库中
None.gif
     public   void  dept_Update(Object sender, GridViewUpdateEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        dept.FooterRow.Enabled 
= false;
InBlock.gif        Dept _dept 
= new Dept();
InBlock.gif        
int dept_ID = Int32.Parse(((Label)dept.Rows[e.RowIndex].Cells[0].Controls[0]).Text);
InBlock.gif        
string dept_Name=((TextBox)dept.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
InBlock.gif           
// ……进行相关的更新打操作
InBlock.gif
        deptDataBind();
InBlock.gif
ExpandedBlockEnd.gif    }

None.gif         
// 进行分页显示
None.gif
     public   void  dept_PageIndexChanging( object  sender, GridViewPageEventArgs e)
ExpandedBlockStart.gifContractedBlock.gif    
dot.gif {
InBlock.gif        dept.PageIndex 
= e.NewPageIndex;
InBlock.gif        deptDataBind();
ExpandedBlockEnd.gif    }

None.gif

转载于:https://www.cnblogs.com/lovenets/archive/2007/01/29/632835.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值