C# 单击“标签”时,单击“在行激发栅格视图”命令

C# 单击“标签”时,单击“在行激发栅格视图”命令,c#,asp.net,gridview,webforms,C#,Asp.net,Gridview,Webforms,当我单击GridView的标签时,我很难执行RowCommand 这是我的gridview代码 <asp:GridView ID="JobsGridView" runat="server" OnRowCommand="JobsGridView_RowCommand" EmptyDataText="No builds found" HeaderStyle-CssClass="HeaderColors" AutoGenerateColumns="False" ShowHeader="false

当我单击GridView的标签时,我很难执行RowCommand

这是我的gridview代码

<asp:GridView ID="JobsGridView" runat="server" OnRowCommand="JobsGridView_RowCommand" EmptyDataText="No builds found" HeaderStyle-CssClass="HeaderColors" AutoGenerateColumns="False" ShowHeader="false">
  <Columns>
     <asp:ButtonField Text='SingleClick' CommandName="SingleClick" Visible="False"/>
     <asp:TemplateField>
         <ItemTemplate>
             <asp:Label ID="JobIdLabel" runat="server" Text='<%# Bind("BrokenProject") %>' ></asp:Label>
         </ItemTemplate>
     </asp:TemplateField>
   </Columns>
 <RowStyle Width="100%" CssClass=""></RowStyle>
</asp:GridView>

单击标签时如何调用
JobsGridView\u row命令
函数?如果我让buttonfield可见,我可以看到按钮旁边有SingleClick,它确实调用了函数,但我不想要这个额外的按钮。我只想单击列表上的名称,然后发生一些事情


我知道期望点击标签做任何事情似乎很愚蠢,但似乎标签没有任何事件,我一直在看一些类似的代码,它们会这样做…

除非您想编写Javascript来处理点击,否则您将需要一个具有回发到服务器功能的控件,就像Andrei提到的那样。输入(例如按钮)和超链接可以做到这一点。

您可以使用链接按钮

<asp:LinkButton ID="JobIdLink" runat="server"
    CommandName="SomeCommand"
    Text='<%# Bind("BrokenProject") %>' >
</asp:LinkButton>

你将不会有标签运气。也许可以尝试在客户机上看不到的行中创建一个链接按钮,并模拟单击它。或者手动使用
\uu doPostBack
提出请求。我同意@Andrei。LinkButton就是解决方案。您可以使用CSS使其看起来像标签。
a:link
{ 
    color: black; 
    text-decoration: none;
}

a:visited
{ 
    color: black; 
    text-decoration: none;
}

a:hover
{
    color: black; 
    text-decoration: none;
}