在gridview中有一列中用linkbutton控件做了超链接,我想每次点击超链接触发一个事件,好更新数据库中一个数值,如下
Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
        if e.CommandName ="link" then
         
        End If
end sub



<asp:TemplateField ><ItemTemplate>
     <asp:LinkButton ID="LinkButton1" runat="server" CommandName ="link" CausesValidation="false"  CommandArgument ='<%#Eval("bblink") %>' OnClick ="LinkButton1_Click" Text='<%eval("bbid") %>' PostBackUrl=“......” >下载...</asp:LinkButton>
</ItemTemplate> </asp:TemplateField>
但是怎么也不能激发rowcommand事件,如果换成
<asp:ButtonField Text="按钮" CommandName ="link"  />就能激发rowcommand事件,但是又能实现超链接,请问为什么,我搜了baidu好长时间都不能解决,谢谢了

解决方案 »

  1.   

    因为LinkButton只是自定义列中的控件,它没有定义RowCommand事件,点它只会出发超链接
    而ButtonField是按钮列,点它会触发RowCommand事件
      

  2.   

    LinkButton一样可以触发rowcommand事件~            <asp:TemplateField>
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" runat="server" CommandName="link">LinkButton</asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
            protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                if (e.CommandName == "link")
                {
                    Response.Write("test");
                }
            }
      

  3.   

    Sub   GridView1_RowCommand(ByVal   sender   As   Object,   ByVal   e   As   GridViewCommandEventArgs) 
                    if   e.CommandName   ="link"   then 
                       
                    End   If 
    end   sub 
    。 
    。 
    。 
    <asp:TemplateField   > <ItemTemplate> 
              <asp:LinkButton   ID="LinkButton1"   runat="server"   CommandName   ="link"        CausesValidation="false"     CommandArgument   =' <%#Eval("bblink")   %> '   OnClick   ="LinkButton1_Click"   Text=' <%eval("bbid")   %> '   PostBackUrl=“......”   > 下载... </asp:LinkButton> 
    </ItemTemplate>   </asp:TemplateField> 
    我的和2楼的仁兄有什么不同,为什么不能触发rowcommand事件?????????????????
    帮帮忙吧
      

  4.   

    不知你为什么要设置LinkButton的PostBackUrl?
    既然要触发RowCommand,LinkButton1_Click,何必再要跳转页面?
      

  5.   

    Sub  GridView1_RowCommand(ByVal sender As Object,ByVal e As GridViewCommandEventArgs)   
        if e.CommandName ="link" then   
           
         End  If   
    end sub   
    。   
    。   
    。   
    <asp:TemplateField ><ItemTemplate>   
        <asp:LinkButton  ID="LinkButton1" runat="server"  CommandName="link" CausesValidation="false"           CommandArgument='   <%#Eval("bblink")       %>' Text='<%eval("bbid")%>' PostBackUrl=“......”>下载... </asp:LinkButton>   
    </ItemTemplate></asp:TemplateField>   我只是想要一个事件,点击超链接就触发的事件,LinkButton1_Click 我也试过了,也不能激发
    上边的代码我去掉了LinkButton1_Click ,也不能激发rowcommand事件
      

  6.   


    <asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand">检查一下OnRowCommand="GridView1_RowCommand"有没有~也就是事件关联起来没~
      

  7.   


            protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
            {
                if (e.CommandName == "link")
                {
                    Response.Write("test");
                }
            }
    这样应该可以呀。
      

  8.   

    <asp:GridView ID="GridView1" runat="server" DataKeyNames="bbid"  AutoGenerateColumns="False" CellPadding="4" DataSourceID="AccessDataSource1" ForeColor="#333333" GridLines="None" OnRowCommand ="GridView1_RowCommand" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoGenerateSelectButton="True">
    GridView1_RowCommand有呀
    不知道为什么
      

  9.   

    PostBackUrl="........"
    这里跳转了~so 没有执行GridView1_RowCommand
      

  10.   

    看你的需求~也没必要用PostBackUrl~去掉就行了~
      

  11.   

    你设置EnableViewState="True"就OK了