Gridview imagebutton onclick 和 OnCommand 事件不会被触发。
<form id="form1" runat="server">
<div class="heading">
<div class="Search">
<customContorls:Header ID="Header1" runat="server" />
</div>
<div class="MenuItems">
<customContorls:MenuItems ID="MenuItems1" runat="server" />
</div>
</div>
<div class="content-wrapper">
<div style="margin-left: 50px">
<asp:GridView ID="grdResult" runat="server" OnRowCommand="grdResult_RowCommand" AllowPaging="true" EmptyDataText="No Video Found"
AlternatingRowStyle-HorizontalAlign="Center" GridLines="None" DataSourceID="objSource"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ImageUrl='<%# Eval("Thumbnail") %>' runat="server" Width="200" Height="150"
ID="imgThumbnail" CommandName="ABC" CommandArgument="123"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="VideoName" SortExpression="VideoName"></asp:BoundField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="objSource" runat="server"
TypeName="PagingSource" SortParameterName="sortExpression"
OldValuesParameterFormatString="original_{0}" EnablePaging="True"
SelectMethod="GetVideoDataBy" SelectCountMethod="TotalNumberOfRecords"></asp:ObjectDataSource>
</div>
</div>
</form>
这是我使用 ObjectDataSource 的完整标记代码,因为数据源分页/真实分页
这是C#代码
protected void Page_Load(object sender, EventArgs e)
{
Title = "Search Result";
string SortExp = "";
if (!IsPostBack)
{
if (Page.RouteData.Values["videoname"] != null)
SortExp = Page.RouteData.Values["videoname"].ToString();
grdResult.Sort(SortExp, SortDirection.Ascending);
grdResult.PageSize = 5;
}
}
protected void grdResult_RowCommand(object sender, GridViewCommandEventArgs e)
{
if(e.CommandName == "ABC")
{
Response.Redirect("~/video.aspx", false);
}
}
我也尝试过 OnRowCommand 事件,但它也没有被触发。