首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用System.FormatException后接收ClientScript

使用System.FormatException后接收ClientScript
EN

Stack Overflow用户
提问于 2011-02-02 13:12:18
回答 1查看 1.1K关注 0票数 2

我试图使用以下代码为GridView编写onclick行为代码:

代码语言:javascript
复制
protected void gridProcesses_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';";
        e.Row.Attributes["onmouseout"] = "this.style.textDecoration='none';";
        e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gridProcesses, "SelectProcess$" + e.Row.Cells[0].Text);
    }
}

protected override void Render(HtmlTextWriter writer)
{
    foreach(GridViewRow row in gridProcesses.Rows)
    {
        if (row.RowType == DataControlRowType.DataRow)
            this.ClientScript.RegisterForEventValidation(this.gridProcesses.UniqueID, "SelectProcess$" + row.Cells[0].Text);
    }
    base.Render(writer);
}

protected void gridProcesses_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "SelectProcess")
    {
       //do stuff after click on gridviewrow
    }
}

编译并单击GridViewRow之后,将调用我的gridProcesses_RowCommand并输入"if",因为SelectProcess是以CommandName的形式传递的,我在该代码中所做的任何操作都是有效的,但是在抛出以下错误之后,程序就会停止工作:

代码语言:javascript
复制
System.Web.HttpUnhandledException (0x80004005): Eine Ausnahme vom Typ "System.Web.HttpUnhandledException" wurde ausgelöst. ---> System.FormatException: Input string was not in a correct format.
   bei System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   bei System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   bei System.Convert.ToInt32(String value, IFormatProvider provider)
   bei System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup)
   bei System.Web.UI.WebControls.GridView.RaisePostBackEvent(String eventArgument)
   bei System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   bei System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   bei System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   bei System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   bei System.Web.UI.Page.HandleError(Exception e)
   bei System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   bei System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
   bei System.Web.UI.Page.ProcessRequest()
   bei System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
   bei System.Web.UI.Page.ProcessRequest(HttpContext context)
   bei ASP.processes_aspx.ProcessRequest(HttpContext context) in c:\Users\roett04\AppData\Local\Temp\Temporary ASP.NET Files\root\4c906b5d\4377a67f\App_Web_qcvmvpfq.0.cs:Zeile 0.
   bei System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   bei System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

如果我添加一个SelectButton并使用OnSelectedIndexChanging,而不是覆盖呈现方法和使用行数据库添加onclick-处理程序,相同的代码就能正常工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-02-02 13:20:29

GridView控件支持使用事件的CommandArgument属性作为页码的Page命令。在转换此属性时,它似乎失败了。

您是否有可能在e.CommandArgument块之外为if分配一些东西?如果是这样的话,就不应该这样做,因为它会影响SelectProcess以外的其他命令。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4874850

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档