我有一个带有gridview的asp页面。我还为每个绑定行添加了一个clientscript,以突出显示鼠标上/下的非高亮显示。我添加了一个asp:按钮作为模板字段并将值绑定到CommandArgument。在IE和FIrefox中,我得到了CommandName传递给_RowCommand事件的预期行为。但是,在Safari中我只看到传递给RowCommand的CommanName“Select”。
预期的行为是,当单击绑定行时,“Select”参数将传递给RowCommand事件。单击行中的Button时,将传递参数“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;
}
}
itemtemplate的HTML
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnRemove" runat="server" Text="Remove" CommandName="Remove" OnClientClick="return confirmRemove();"
CommandArgument='<%# Eval("ID") %>' />
</ItemTemplate>
任何想法都将不胜感激。感谢
答案 0 :(得分:0)
我认为您首先应该检查按钮是否被点击从哪个浏览器以及它是否来自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;
}
}