【问题标题】:Gridview RowCommand arguments not passing correctly in SafariGridview RowCommand 参数未在 Safari 中正确传递
【发布时间】:2015-03-22 01:31:32
【问题描述】:

我有一个带有gridview 的asp 页面。我还为每个绑定行添加了一个客户端脚本,以突出显示/取消突出显示鼠标悬停/移出。我添加了一个 asp:button 作为模板字段并将一个值绑定到 CommandArgument。在 IE 和 FIrefox 中,我得到了将 CommandName 传递给 _RowCommand 事件的预期行为。但是,在 Safari 中,我只看到传递给 RowCommand 的“Select”的 CommanName。

预期的行为是,当单击绑定行时,“选择”参数将传递给 RowCommand 事件。单击该行中的按钮时,将传递参数“Remove”。

protected void gvContacts_RowDataBound(object sender, GridViewRowEventArgs e)
{

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes.Add("onMouseOver", "Highlight(this)");
        e.Row.Attributes.Add("onMouseOut", "UnHighlight(this)");

        e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(gvContacts, "Select$" + e.Row.RowIndex);

        e.Row.Attributes["style"] = "cursor:pointer";
    }
}


protected void gvContacts_RowCommand(object sender, GridViewCommandEventArgs e)
{                

    switch (e.CommandName)  //Always "Select" when browser is Safari.  
    {
        case "Select":
            Session["clientID"] = gvContacts.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text;
            Response.Redirect("../Contacts/ContactEdit.aspx?readin=1");
            break;
        case "Remove":
            //Remove the client from the list
            Company company = new Company();
            company.Get(Int32.Parse(Session["CompanyID"].ToString()), ((Model)Session["model"]).ConnectionString);
            company.RemoveUser(Int32.Parse(e.CommandArgument.ToString()));
            BindGrid(company.ID);
            break;
    }                
}

项目模板的 HTML

<asp:TemplateField>
    <ItemTemplate>
        <asp:Button ID="btnRemove" runat="server" Text="Remove" CommandName="Remove" OnClientClick="return confirmRemove();"
                                    CommandArgument='<%# Eval("ID") %>' />
   </ItemTemplate>

任何想法将不胜感激。谢谢

【问题讨论】:

  • 您给了命令名称“REMOVE”,那么行命令事件如何理解从 safari 中单击了该按钮,如果是,那么您没有提及它的代码...

标签: asp.net gridview rowcommand


【解决方案1】:

我认为您应该首先检查按钮是从哪个浏览器单击的,如果它来自 safari,而不是更改命令名称..

  protected void gvContacts_RowCommand(object sender, GridViewCommandEventArgs e)
    {                
    System.Web.HttpBrowserCapabilities browser = Request.Browser;
      if(browser.Browser=="Safari") //Check The Browser 
       {
          e.CommandName="Select";
       }
        switch (e.CommandName)  //Always "Select" when browser is Safari.  
        {
            case "Select":
                Session["clientID"] = gvContacts.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text;
                Response.Redirect("../Contacts/ContactEdit.aspx?readin=1");
                break;
            case "Remove":
                //Remove the client from the list
                Company company = new Company();
                company.Get(Int32.Parse(Session["CompanyID"].ToString()), ((Model)Session["model"]).ConnectionString);
                company.RemoveUser(Int32.Parse(e.CommandArgument.ToString()));
                BindGrid(company.ID);
                break;
        }                
    }

【讨论】:

    猜你喜欢
    • 2014-11-24
    • 2012-07-30
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-20
    相关资源
    最近更新 更多