网格视图链接按钮未点击asp.net?

时间:2017-07-27 07:06:12

标签: c# asp.net gridview hyperlink

网格视图链接按钮(其中一列)onclick未触发。真的无法理解做错了什么。需要帮忙。新秀编码。

的.aspx

     <asp:GridView ID="gridTSRJOBList" runat="server" AutoGenerateColumns="False" CssClass="table table-striped table-bordered dataTable print-first-column-hide" CellSpacing="0" Width="100%"  ShowHeaderWhenEmpty="True" EmptyDataText="No TSR JOB Found for this Lease" GridLines="None" DataKeyNames="JobID"role="grid">                       
<Columns>
<asp:TemplateField HeaderText="Job" ItemStyle-HorizontalAlign="Left">
 <ItemTemplate>
 <asp:LinkButton runat="server" ID="lnkJobID" CommandArgument='<%# Eval("JobID") %>' Text='<%#Eval("JobID") %>'  OnClick="lnkJobID_Click"></asp:LinkButton></ItemTemplate>
</asp:TemplateField>
 <asp:BoundField DataField="CategoryID" HeaderText="Category" ReadOnly="True"  />
<asp:BoundField DataField="JobDetail" HeaderText="Short Description" ReadOnly="True" />
 <asp:BoundField DataField="JobType" HeaderText="Job Status" ReadOnly="True" />
  <asp:BoundField DataField="CustomerReference" HeaderText=" Customer Reference" ReadOnly="True" />
 </Columns>
 </asp:GridView>

C#代码

protected void lnkJobID_Click(object sender, EventArgs e)
{
    try {
        LinkButton jobLinkbutton = new LinkButton();
        jobLinkbutton = (LinkButton)sender;
        Response.Redirect("TSR_proc.aspx?bl=1&JOBID=" + jobLinkbutton.CommandArgument);

    } catch (Exception ex) {
    }
}

1 个答案:

答案 0 :(得分:0)

从linkbutton取消lnkJobID_Click并添加CommandName='clickLink'。 您可以在Gridview RowCommand事件中管理此事件,在您的情况下

gridTSRJOBList_RowCommand