点击按钮事件

protectedvoid 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>
posted on 2011-05-12 13:19  高兴happy  阅读(877)  评论(0编辑  收藏  举报