使用asp.net从Datagrid中选择特定行 [英] Selection of Particular Row From a Datagrid using asp.net

查看:93
本文介绍了使用asp.net从Datagrid中选择特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在itemcommand事件和switch case中使用rowindex和参数异常从Datagrid中选择特定行。我已经插入了代码。当我运行应用程序时,它显示错误"输入字符串格式不正确" ;
$

I want to select the particular row from Datagrid using rowindex and argument exception inside itemcommand event and switch case.Below i have inserted the code.When I run the application it shows the error "input string was not in a correct format"

protected void DataGrid1_ItemCommand(object sender,DataGridCommandEventArgs e)
{
try
{
lblMessage.Text="";
ObjBOAdvance=new BOAdvance();
objBLAdvance =new BLAdvance();
string strResult=string.Empty;
switch(e.CommandName.ToUpper e)
{
case "EDIT":
{
Table1.Visible=false;
Table2.Visible=true;
btnADD.Text="ADD";
objBOAdvance.Operationid=5;
DataTable dtLType =objBLAdvance.BL_getFCdetailsLedger(objBOadvance);
int rowindex=Convert.ToInt32(e.CommandArgument);
txtAdvance.Text=dtLType.Rows[rowindex]["totalAmount"].ToString();
lblreqID.Text=dtLType.Rows[rowindex]["reqID"].ToString();
TextBox1.Text=dtLType.Rows[rowindex]["empname"].ToString().Trim();
TextBox2.Text=dtLType.Rows[rowindex]["DesigShort"].ToString().Trim();
Label11.Text=dtLType.Rows[rowindex]["ProjectID"].ToString();
Label14.Text=dtLType.Rows[rowindex]["Project_Category"].ToString();
objBOAdvance.req_ID=Convert.ToInt16(lblreqID.Text);
txtproject.Text=Label14.Text;
break;
}
BindFinalClaim();
catch(Exception ex)
{
throw new Exception(ex.Message);
}
}




推荐答案

Hi Litty Alex,

Hi Litty Alex,

>>输入字符串格式不正确"

>>input string was not in a correct format"

我怀疑此错误发生在  int rowindex = 转换 ToInt32 e CommandArgument );

I suspect this error happens at int rowindex=Convert.ToInt32(e.CommandArgument);

我是对的吗?如果没有,请感受免费让我知道。如果是,请继续下一步。

Am I right? If not, please feel free to let me know. If yes, please continue to next.

错误意味着您尝试解析整数的字符串实际上并不包含有效整数。

The error means that the string you're trying to parse an integer from doesn't actually contain a valid integer.

在创建表单时, e CommandArgument 极不可能立即包含有效整数 - 请查看
Int.TryParse 方法 - 如果字符串可能实际上不包含整数,则更容易使用 - 它不会抛出异常,因此更容易从中恢复。

It's extremely unlikely that the e.CommandArgument will contain a valid integer immediately when the form is created - check out the Int.TryParse method - it's much easier to use if the string might not actually contain an integer - it doesn't throw an exception so it's easier to recover from.

我还建议您查看一下以下类似的主题

I also suggest you have a look the following similar threads

https://forums.asp.net/t/1791563.aspx?Input+string+was+not+in+a+correct+format+when+LinkBut​​ton + +单击+在+ GridView中

gridview e.CommandArgument字符串格式不正确

祝你好运,

Kristin


这篇关于使用asp.net从Datagrid中选择特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆