输入字符串的格式不正确。

编程入门 行业动态 更新时间:2024-10-28 17:22:36
本文介绍了输入字符串的格式不正确。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

此代码在加载页面时正常工作。当我清除所有控件并再次添加时,我收到此错误。请告诉我哪里做错了。 我尝试过:

case StepTransition: if (UIControlsWizard.WizardSteps.Count == 0 ) { rbtnAddWizard.Attributes.Add( WizardCommand, CreateWizard& + commandData [ 2 ] + & + commandData [ 1 ]); RadScriptManager.RegisterClientScriptBlock( this , this .GetType(), btnClick _, document.getElementById(' + rbtnAddWizard.ClientID + ')。click();, true ); } break ;

受保护 void rbtnAddWizard_Click( object sender, EventArgs e) { string wizardCommand = rbtnAddWizard.Attributes [ WizardCommand]; if (!string.IsNullOrEmpty(wizardCommand)) { if (wizardCommand.Contains( CreateWizard)) CreateDynamicWizardSteps(Convert.ToInt32( wizardCommand.Split(' &')[ 2 ]),Convert.ToInt32(wizardCommand.Split(' &')[ 1 ])); // 这里我收到错误 else if (wizardCommand.Contains( RemoveWizardAndAdd)) { i f (UIControlsWizard.WizardSteps.Count!= 0 ) RemoveDynamicWizardSteps(); CreateDynamicWizardSteps(Convert.ToInt32(wizardCommand.Split(' &')[ 2 ]),Convert.ToInt32(wizardCommand.Split(' & ;')[ 1 ])); } else if (wizardCommand.Contains( RemoveWizard)) { RemoveDynamicWizardSteps(); // RadScriptManager.RegisterClientScriptBlock(this,this.GetType(),Script,stepChange() ,true); } } }

解决方案

拆分中的一个项目不是整数。 而不是使用 Convert.ToInt32 尝试使用 Int32.TryParse [ ^ ] - 至少你可以找到有问题的字符串 编辑:示例(未经测试)

if(wizardCommand .Contains(CreateWizard)) { int chk1; int chk2; if(int32.TryParse(wizardCommand.Split('&')[2],out chk1)&& int32.TryParse(wizardCommand.Split('&')[1] ,out chk2)) { CreateDynamicWizardSteps(chk1,chk2); } 。 。 。

我个人会做一次拆分并存储结果,然后在后续代码中使用结果,而不是每次我想引用其中一个元素时进行拆分

This code works fine when the page is loading. when i am clearing all the controls and adding once again i am getting this error. Please give an idea where i had done wrong. What I have tried:

case "StepTransition": if (UIControlsWizard.WizardSteps.Count == 0) { rbtnAddWizard.Attributes.Add("WizardCommand", "CreateWizard&" + commandData[2] + "&" + commandData[1]); RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "btnClick_", "document.getElementById('" + rbtnAddWizard.ClientID + "').click();", true); } break;

protected void rbtnAddWizard_Click(object sender, EventArgs e) { string wizardCommand = rbtnAddWizard.Attributes["WizardCommand"]; if (!string.IsNullOrEmpty(wizardCommand)) { if (wizardCommand.Contains("CreateWizard")) CreateDynamicWizardSteps(Convert.ToInt32(wizardCommand.Split('&')[2]), Convert.ToInt32(wizardCommand.Split('&')[1]));//Here i am getting the error else if (wizardCommand.Contains("RemoveWizardAndAdd")) { if(UIControlsWizard.WizardSteps.Count!=0) RemoveDynamicWizardSteps(); CreateDynamicWizardSteps(Convert.ToInt32(wizardCommand.Split('&')[2]), Convert.ToInt32(wizardCommand.Split('&')[1])); } else if (wizardCommand.Contains("RemoveWizard")) { RemoveDynamicWizardSteps(); //RadScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Script", "stepChange()", true); } } }

解决方案

One of the items from your split is not an integer. Instead of using Convert.ToInt32 try using Int32.TryParse[^] - at the very least you will be able to find the offending string Edit: Example (untested)

if (wizardCommand.Contains("CreateWizard")) { int chk1; int chk2; if(int32.TryParse(wizardCommand.Split('&')[2], out chk1) && int32.TryParse(wizardCommand.Split('&')[1], out chk2)) { CreateDynamicWizardSteps(chk1, chk2); } . . .

I would personally do the split once and store the results, then use the results in the subsequent code, rather than doing the split each time I want to reference one of the elements

更多推荐

输入字符串的格式不正确。

本文发布于:2023-06-04 17:29:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/502157.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   不正确   格式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!