Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用ClientScript后接收System.FormatException_C#_Asp.net_Gridview_Clientscript - Fatal编程技术网

C# 使用ClientScript后接收System.FormatException

C# 使用ClientScript后接收System.FormatException,c#,asp.net,gridview,clientscript,C#,Asp.net,Gridview,Clientscript,我试图使用以下代码隐藏代码为GridView编写onclick行为: protected void gridProcesses_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes["onmouseover"] = "this.style.cursor='hand';";

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

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后,将调用我的GridProcesss\u Row命令并输入“if”,因为SelectProcess作为CommandName传递,所以我在该代码中尝试执行的任何操作都有效,但随后程序在抛出以下错误后停止工作:

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并使用OnSelectedIndexChanged而不是重写render方法并使用rowdatabound添加onclick处理程序,同样的代码也可以正常工作

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


您是否可能在
if
块之外为
e.CommandArgument
分配了一些内容?如果是这种情况,你不应该这样做,因为它会影响除
SelectProcess

之外的其他命令。你的意思是说
处的代码引发异常如果
lineNo,那么代码执行得很好,但是,弗雷德里克刚刚发布了我想要的答案!太棒了,真是太棒了,非常感谢!我在GridView中将CommandArgument设置为Textvalue,但不知道它可能会影响其他命令。我遇到了同样的问题,但没有在任何地方设置e.CommandArgument-有什么想法吗?