vb.net 如何处理gridview中链接按钮的点击事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25405939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to handle click event of link button inside gridview
提问by Kishor Rajendra Kulkarni
I have a gridview with some link buttons. What i am trying to do is when i click on link button, two buttons i.e. (Export to CSV and Export To Excel) will be shown. But when i am clicking on any link button, nothing is happening... Heres my code...
我有一个带有一些链接按钮的网格视图。我想要做的是当我点击链接按钮时,将显示两个按钮,即(导出到 CSV 和导出到 Excel)。但是当我点击任何链接按钮时,什么也没有发生......这是我的代码......
Gridview:
网格视图:
<asp:GridView ID="grd_ComplaintCount" runat="server" AutoGenerateColumns="False"
CellPadding="4" EnableModelValidation="True" ForeColor="#333333"
GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Total Complaint">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbtn_TotalComplaint" CommandName="Total"
Text='<%#Bind("TotalComplaint") %>' CommandArgument="Total"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Open Complaint">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbtn_TotalOpenComplaint" CommandName="Open"
Text='<%#Bind("TotalOpen") %>' CommandArgument="Open"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Closed Complaint">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbtn_TotalCloseComplaint" CommandName="Closed"
Text='<%#Bind("TotalClose") %>' CommandArgument="Closed"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Reassigned Complaint">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbtn_TotalReassignedComplaint" CommandName="Reassign"
Text='<%#Bind("TotalMemberReAssign") %>' CommandArgument="Reassigned"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Observation Complaint">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lbtn_TotalObservationComplaint" CommandName="Obeservation"
Text='<%#Bind("TotalObservation") %>' CommandArgument="Observation"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
And this is my code..
这是我的代码..
Protected Sub grd_ComplaintCount_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grd_ComplaintCount.RowCommand
ComplaintCount_Detail(e.CommandArgument)
If e.CommandName = "Total" Or e.CommandName = "Open" Or e.CommandName = "Closed" Or e.CommandName = "Reassign" Or e.CommandName = "Obeservation" Then
btnexptocsv.Visible = True
btnexptoexcel.Visible = True
End If
End Sub
I know i have done some mistakes...
我知道我犯了一些错误...
回答by Harish
1.Change asp:LinkButtonmarkup and specify CommandName
1.更改asp:LinkButton标记并指定CommandName
commandname="Select" text='<%# Eval("MEO_NR") %>'>
2.Create a RowCommandEvent
2.创建一个 RowCommandEvent
OnRowCommand="GVActiveMEOs_OnRowCommand"
Code-behind
代码隐藏
Protected Sub gridview1_RowCommand(sender As Object, e As GridViewCommandEventArgs)
Dim meonum As String = DirectCast(e.CommandSource, LinkButton).CommandArgument
End Sub
Always remember that the clicked row is not a SelectedRowunless you specify the CommandNameas CommandName="Select"
永远记住,被点击的行不是 aSelectedRow除非你指定CommandNameasCommandName="Select"

