GridView Row命令未触发

时间:2015-07-09 12:17:35

标签: c# asp.net gridview

我在网格视图中放置了一个linkbutton,它似乎拒绝在单击时触发row命令事件。

当我把数据绑定器从!Page.IsPostBack中取出时,它很奇怪但是这没用多少,因为无论如何它总是返回第一行。

在网页发布回来后,网格中的数据似乎也消失了。

我的代码如下,任何帮助都将不胜感激。

<asp:GridView ID="gvContactHistory" runat="server" CssClass="contactHistory" AutoGenerateColumns="false" OnRowCommand="gvContactHistory_RowCommand">
<Columns>
    <asp:BoundField HeaderText="Date:" DataField="CreatedOn" DataFormatString="{0:dd/MM/yyyy}" />
    <asp:BoundField HeaderText="Time:" DataField="CreatedOn" DataFormatString="{0:hh:mmtt}" />
    <asp:BoundField HeaderText="Format:" DataField="Type" />
    <asp:TemplateField HeaderText="" ItemStyle-Width="150">
        <ItemTemplate>
            <asp:LinkButton ID="lbLoadDetails" runat="server" CommandArgument='<%# Eval("Id") %>' CommandName="Details" CausesValidation="false">
                <i class="icon-down-arrow"></i>
            </asp:LinkButton>
        </ItemTemplate>
    </asp:TemplateField>
</Columns>

背后的代码

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        Account account = ClickHelpers.GetSelectedAccount();

        if (account != null)
        {
            SetupContactHistory(account);
        }
    }
}

private void SetupContactHistory(Account account)
{
    var activities = ClickHelpers.GetAccountActivities(account);

    if (activities != null)
    {
        gvContactHistory.DataSource = activities;
        gvContactHistory.DataBind();
    }
}

protected void gvContactHistory_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Details")
    {
        Guid id = ValidationHelper.GetGuid(e.CommandArgument, Guid.Empty);
        Account account = ClickHelpers.GetSelectedAccount();
        var activity = ClickHelpers.GetAccountActivity(account, id);
    }
}

0 个答案:

没有答案