博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP.Net GridView 基础 Template模板
阅读量:4610 次
发布时间:2019-06-09

本文共 4229 字,大约阅读时间需要 14 分钟。

一、了解Template

AlternatingItemTemplate定义交替行的内容和外观,如果没有规定模板,则使用ItemTemplate;

EditItemTemplate定义当前正在编辑的行的内容和外观。该模板包含输入字段,而且还可能包含验证程序;
FooterTemplate定义该行的页脚的内容和外观;
HeaderTemplate定义该行的标题的内容和外观;
ItemTemplate定义该行的默认内容和外观。

二、模板应用

 

 

aspx代码

其它字段
Link1
Link2
Link3
Link4
  

 aspx.cs代码

///         /// 2、模板中自定义Button和CommandArgument        ///         protected void btnDel_Click(object sender, EventArgs e)        {            string strCommandArgument = ((Button)sender).CommandArgument;            ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('" + strCommandArgument + "')",true);        }        ///         /// 1、ButtonField和RowCommand        ///         protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)        {            //1、ButtonField和RowCommand            if (e.CommandName == "1")             {                //在ButtonField中CommandArgument属性是当前行索引(RowIndex)不需要开发人员设置                int intRowIndex = int.Parse(e.CommandArgument.ToString());                string strConferenceNo = GridView1.Rows[intRowIndex].Cells[0].Text.ToString();                ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('" + strConferenceNo + "')", true);            }            //3、模板中自定义Button和RowCommand            if (e.CommandName == "2")            {                //自定义Button中CommandArgument属性是开发人员设置                string strConferenceNo = e.CommandArgument.ToString();                ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('" + strConferenceNo + "')", true);            }            //4、模板中自定义Button和RowCommand            if (e.CommandName == "3")            {                //在RowDataBound针对模板中自定义Button的CommandArgument赋值                int intRowIndex = int.Parse(e.CommandArgument.ToString());                string strConferenceNo = GridView1.Rows[intRowIndex].Cells[0].Text.ToString();                ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('" + strConferenceNo + "')", true);            }            //5、模板中自定义Button和RowCommand            if (e.CommandName == "4")            {                //CommandArgument='<%# ((GridViewRow)Container).RowIndex %>'                int intRowIndex = int.Parse(e.CommandArgument.ToString());                string strConferenceNo = GridView1.Rows[intRowIndex].Cells[0].Text.ToString();                ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('" + strConferenceNo + "')", true);            }        }        ///         /// 行绑定事件        /// 1、常用于行选择事件注册        /// 2、特殊数据处理        ///         protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)        {            //4、针对模板中自定义Button的CommandArgument赋值            if (e.Row.RowType == DataControlRowType.DataRow)            {                LinkButton lnk = (LinkButton)e.Row.FindControl("LinkButton2");                lnk.CommandArgument = e.Row.RowIndex.ToString();            }        }        ///         /// GridView行创建后        ///         protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)        {            //5、针对模板中自定义Button的CommandArgument赋值            if (e.Row.RowType == DataControlRowType.DataRow)            {                LinkButton lnk = (LinkButton)e.Row.FindControl("LinkButton4");                lnk.Click += new EventHandler(lnk_Click);//按+=再按2次Tab键,实现快速注册事件            }        }        void lnk_Click(object sender, EventArgs e)        {            //获取当前行            GridViewRow grdRow = (GridViewRow)((LinkButton)sender).Parent.Parent;            string strConferenceNo = grdRow.Cells[0].Text.ToString();            ClientScript.RegisterStartupScript(this.GetType(), "alter", "alert('" + strConferenceNo + "')", true);        }

  

 

转载于:https://www.cnblogs.com/WarBlog/p/9156864.html

你可能感兴趣的文章
关于Cocos2d-x中背景音乐和音效的添加
查看>>
checkbox和文字对齐
查看>>
%s的用法
查看>>
java中==和equals
查看>>
CCActionPageTurn3D
查看>>
python random
查看>>
esp32-智能语音-cli(调试交互命令)
查看>>
netty与MQ使用心得
查看>>
关于dl dt dd 文字过长换行在移动端显示对齐的探讨总结
查看>>
swoolefy PHP的异步、并行、高性能网络通信引擎内置了Http/WebSocket服务器端/客户端...
查看>>
Python学习笔记
查看>>
unshift()与shift()
查看>>
使用 NPOI 、aspose实现execl模板公式计算
查看>>
行为型模式:中介者模式
查看>>
How to Notify Command to evaluate in mvvmlight
查看>>
33. Search in Rotated Sorted Array
查看>>
461. Hamming Distance
查看>>
Python垃圾回收机制详解
查看>>
jquery 编程的最佳实践
查看>>
MeetMe
查看>>