asp.net gridview itemtemplate中控件事件获取行参数
2013-09-25 22:15
531 查看
gridview中加入了一列linkbutton,但是在rowcommand事件中,不能读取出来其中的行(e.commandAgurments),通过查阅资料,发现可以这么解决。
msdn中的解释是
呈现 GridView 控件之前,必须先为该控件中的每一行创建一个 GridViewRow 对象。 在创建 GridView 控件中的每一行时,将引发 RowCreated 事件。 这使您可以提供一个这样的事件处理方法,即每次发生此事件时就执行一个自定义例程(如在行中添加自定义内容)。
GridViewRowEventArgs 对象将传递给事件处理方法,以便您可以访问正在创建的行的属性。 若要访问行中的特定单元格,请使用 GridViewRowEventArgs 对象的 Cells 属性。 使用 RowType 属性可确定正在创建的是哪一种行类型(标题行、数据行等等)。
以此获得行参数。
protected void gv_city_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "shenpi")//AAAA { int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = gv_city.Rows[index]; Session["user_numB"] = row.Cells[1].Text.ToString(); Response.Write("<script> alert('" + Session["user_numB"] + "'); </script>"); //Response.Redirect("/login.aspx"); } } protected void gv_city_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //Retrieve the LinkButton control from the first column. LinkButton lb_shenpi = (LinkButton)e.Row.FindControl("lb_shenpi"); // Set the LinkButton's CommandArgument property with the row's index. lb_shenpi.CommandArgument = e.Row.RowIndex.ToString(); } }
msdn中的解释是
呈现 GridView 控件之前,必须先为该控件中的每一行创建一个 GridViewRow 对象。 在创建 GridView 控件中的每一行时,将引发 RowCreated 事件。 这使您可以提供一个这样的事件处理方法,即每次发生此事件时就执行一个自定义例程(如在行中添加自定义内容)。
GridViewRowEventArgs 对象将传递给事件处理方法,以便您可以访问正在创建的行的属性。 若要访问行中的特定单元格,请使用 GridViewRowEventArgs 对象的 Cells 属性。 使用 RowType 属性可确定正在创建的是哪一种行类型(标题行、数据行等等)。
以此获得行参数。
相关文章推荐
- 菜鸟学Asp.Net——GridView控件之RowDataBind事件中如何获取已绑定的数据
- 怎样为数据控件Itemtemplate内的控件添加事件[ASP.NET]
- [ASP.NET]DataList中获取FooterTemplate中控件的研究
- asp.net获得数据控件事件索引并获取其中值总结
- 解决asp.net FileUpload控件无法获取完整路径的问题 - 无序修改浏览器参数
- 获取当前页面触发事件的控件(asp.net)
- Asp.net 中 GridView 在 RowDataBound事件中获取 某列值 的方法
- Asp.net之获取GridView控件中TextBox等控件的值
- 获取Asp.net GridView控件当中总的记录数量
- ASP.NET DEMO 5:如何在GridView的RowCommand事件中获取当前的GridViewRow
- ASP.NET 2.0数据教程之十二:在GridView控件中使用TemplateField(转)
- C#.NET GridView 中如何获取脚中的控件ID并添加客户端事件
- 在ASP.NET的GridView(CommandField、ButtonField、ItemTemplate)里的刪除Button加入Confirm的用法
- GridView是ASP.NET中功能强大的数据显示控件,它的RowDataBound事件为我们提供了方便的控制行、列数据的途径。
- ASP.NET GridView_第四篇_控件和HTML标记的容器 TemplateField 模板列
- 获取Asp.net中Treeview控件的Node双击"事件"!
- Asp.net之使用GridView控件的RowCommand事件实现修改和删除
- ASP.NET Postback事件来源控件的获取
- ASP.NET中GridView控件的几个事件的使用
- asp.net中GridView内部点击事件判断是第几行并获取row数据