GridVew linkbutton点击时获取点击行label的绑定值

点击按钮事件

protected void LinkBtnUpdate_Click( object sender, EventArgs e)
{

LinkButton btn
= (LinkButton)sender;
// 找到点击行
GridViewRow irow = (GridViewRow)btn.NamingContainer;
Label lbltag
= (Label)irow.Cells[ 0 ].FindControl( " Label1 " );
string tbtag = lbltag.Text.Trim();
Response.Write(tbtag);
Response.Redirect(
" Update.aspx?url=news1.aspx&NewsType=1&NewsId= " + tbtag + "" );
}

前台绑定:

< asp:GridView ID = " GridTitle " runat = " server " AutoGenerateColumns = " False "
CellPadding
= " 4 " ForeColor = " #333333 " Width = " 100% "
AllowPaging
= " True " AllowSorting = " True "
onrowdatabound
= " GridTitle_RowDataBound "
onpageindexchanging
= " GridTitle_PageIndexChanging " PageSize = " 10 " >
< RowStyle BackColor = " #EFF3FB " />
< Columns >
< asp:TemplateField >
< HeaderTemplate >
序号
</ HeaderTemplate >
< ItemTemplate >
<% # Container.DataItemIndex + 1 %>
</ ItemTemplate >
< ControlStyle Width = " 20px " />
< ItemStyle Width = " 70px " />
</ asp:TemplateField >
< asp:BoundField DataField = " NewsTitle " HeaderText = " 标题 " >
< ControlStyle Width = " 70% " />
</ asp:BoundField >
< asp:TemplateField >
< HeaderTemplate >
操作
</ HeaderTemplate >
< ItemTemplate >
< asp:LinkButton ID = " LinkBtnUpdate " runat = " server " onclick = " LinkBtnUpdate_Click " > 编辑 </ asp:LinkButton >
& nbsp;
< asp:LinkButton ID = " LinkBtnDelete " runat = " server "
onclick
= " LinkBtnDelete_Click " > 删除 </ asp:LinkButton >
</ ItemTemplate >
< ItemStyle Width = " 100px " />
</ asp:TemplateField >
< asp:TemplateField Visible = " false " >
< ItemTemplate >
< asp:Label ID = " Label1 " runat = " server " Text = ' <%#Eval("NewsId") %> ' >& apos; & gt; </ asp:Label >
</ ItemTemplate >
</ asp:TemplateField >
</ Columns >
< FooterStyle BackColor = " #507CD1 " Font - Bold = " True " ForeColor = " White " />
< PagerTemplate >
< table align = " center " width = " 400px " >
< tr >
< td width = " 50px " >
< asp:Label ID = " Label1 " runat = " server "
Text
= " <%# ((GridView)Container.Parent.Parent).PageIndex + 1 %> " />

</ td >
< td width = " 50px " >
/< asp:Label ID = " lblPageCount " runat = " server "
Text
= " <%# ((GridView)Container.Parent.Parent).PageCount %> " />

</ td >
< td width = " 50px " >
< asp:LinkButton ID = " btnFirst " runat = " server " CausesValidation = " False "
CommandArgument
= " First " CommandName = " Page " Text = " 首页 " />
</ td >
< td width = " 50px " >
< asp:LinkButton ID = " btnPrev " runat = " server " CausesValidation = " False "
CommandArgument
= " Prev " CommandName = " Page " Text = " 上一页 " />
</ td >
< td >
< asp:LinkButton ID = " btnNext " runat = " server " CausesValidation = " False "
CommandArgument
= " Next " CommandName = " Page " Text = " 下一页 " />
</ td >
< td width = " 50px " >
< asp:LinkButton ID = " btnLast " runat = " server " CausesValidation = " False "
CommandArgument
= " Last " CommandName = " Page " Text = " 尾页 " />
</ td >
</ tr >
</ table >
</ PagerTemplate >
< PagerStyle ForeColor = " White " HorizontalAlign = " Center " />
< SelectedRowStyle BackColor = " #D1DDF1 " Font - Bold = " True " ForeColor = " #333333 " />
< HeaderStyle BackColor = " #507CD1 " Font - Bold = " True " ForeColor = " White " />
< EditRowStyle BackColor = " #2461BF " />
< AlternatingRowStyle BackColor = " White " />
</ asp:GridView >

转载于:https://www.cnblogs.com/happygx/archive/2011/05/12/2044257.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值