2

次の分離コードを使用して、GridView のオンクリック動作をコーディングしようとしています。

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 として渡されたため、そのコード内で何をしようとしても動作しますが、その後、プログラムは次のエラーをスローした後に動作を停止します。

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)

render-method をオーバーライドし、rowdatabound を使用して onclick-handler を追加する代わりに、SelectButton を追加して OnSelectedIndexChanging を使用すると、同じコードが正常に機能します。

4

1 に答える 1

2

GridViewコントロールは、イベントのプロパティをページ番号として使用Pageできるコマンドをサポートしています。CommandArgumentこのプロパティの変換中に失敗しているようです。

ブロックのe.CommandArgument に何かを割り当てる可能性はありますか? ifその場合は、 以外のコマンドに影響を与えるため、実行しないでくださいSelectProcess

于 2011-02-02T13:20:29.890 に答える