• GridView的事件


       /// <summary>
        
    /// 编辑选中事件
        
    /// </summary>
        
    /// <param name="sender"></param>
        
    /// <param name="e"></param>

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        
    {
            GridView1.EditIndex 
    = e.NewEditIndex;
            databinGrid();
        }


        
    /// <summary>
        
    /// 编辑取消事件
        
    /// </summary>
        
    /// <param name="sender"></param>
        
    /// <param name="e"></param>

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        
    {
            GridView1.EditIndex 
    = -1;
            databinGrid();
        }


        
    /// <summary>
        
    /// 更新事件
        
    /// </summary>
        
    /// <param name="sender"></param>
        
    /// <param name="e"></param>

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        
    {
            bbsjhwType.Id 
    = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
            bbsjhwType.Name 
    = ((TextBox)(GridView1.Rows[e.RowIndex].Cells[1].Controls[0])).Text.ToString().Trim();
            bbsjhwType.Update();
            GridView1.EditIndex 
    = -1;
            databinGrid();
        }


        
    /// <summary>
        
    /// 设置textbox宽度
        
    /// </summary>
        
    /// <param name="sender"></param>
        
    /// <param name="e"></param>

        protected void GridView1_PreRender(object sender, EventArgs e)
        
    {
            
    if (GridView1.EditIndex > -1)
            
    {
                TextBox TXTb 
    = new TextBox();
                
    for (int i = 1; i < 2; i++)
                
    {
                    TXTb 
    = (TextBox)GridView1.Rows[GridView1.EditIndex].Cells[i].Controls[0];
                    TXTb.Width 
    = 50;
                }

            }

        }

        
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        
    {
            bbsjhwType.Id 
    = int.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
            bbsjhwType.Delete(bbsjhwType.Id);
            databinGrid();
        }

        
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        
    {
            
    //如果是绑定数据行 
            if (e.Row.RowType == DataControlRowType.DataRow)
            
    {
                
    if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
                
    {
                    ((LinkButton)e.Row.Cells[
    3].Controls[0]).Attributes.Add("onclick""javascript:return confirm('你确认要删除:\"" + e.Row.Cells[1].Text + "\"吗?它相应的子类将也被删除')");
                }

            }

        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            databinGrid();
        }

    供大家复制.
  • 相关阅读:
    项目中的*签到*小功能!
    亲们,拿到DateTime.Now你是否也是这样比较的?
    <input type="file" />,美化自定义上传按钮
    让你的页面实现自定义的 Ajax Loading加载的体验!
    按回车键提交表单!
    字符串比较大小,CompareTo来搞定!
    巧用Contains可以做到过滤同类项!
    项目开发中遇到的Bug知识整理!
    SharePoint中详细的版本对比
    ASP.NET安全隐患及SharePoint中的Workaround
  • 原文地址:https://www.cnblogs.com/daxia/p/797752.html
Copyright © 2020-2023  润新知