在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好长时间都不能解决,谢谢了
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好长时间都不能解决,谢谢了
而ButtonField是按钮列,点它会触发RowCommand事件
<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");
}
}
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事件?????????????????
帮帮忙吧
既然要触发RowCommand,LinkButton1_Click,何必再要跳转页面?
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事件
<asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand">检查一下OnRowCommand="GridView1_RowCommand"有没有~也就是事件关联起来没~
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "link")
{
Response.Write("test");
}
}
这样应该可以呀。
GridView1_RowCommand有呀
不知道为什么
这里跳转了~so 没有执行GridView1_RowCommand