如何使用分页gridview验证gridview中的空值 [英] How to validate null value in gridview using paging gridview

查看:56
本文介绍了如何使用分页gridview验证gridview中的空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码如下

My code as follows

private void SaveCheckedValues()
      {
          System.Collections.ArrayList userdetails = new System.Collections.ArrayList();
          int index = -1;
          foreach (GridViewRow gvrow in grdRpt.Rows)
          {
              int.Parse((string)grdRpt.DataKeys[gvrow.RowIndex].Value);

              bool result = ((CheckBox)gvrow.FindControl("chkselecdata")).Checked;

              // Check in the Session
              if (Session["CHECKED_ITEMS"] != null)
                  userdetails = (System.Collections.ArrayList)Session["CHECKED_ITEMS"];
              if (result)
              {
                  if (!userdetails.Contains(index))
                      userdetails.Add(index);
              }
              else
                  userdetails.Remove(index);
          }
          if (userdetails != null && userdetails.Count > 0)
              Session["CHECKED_ITEMS"] = userdetails;
      }



在gridview中如下




In gridview as follows

selectdata  transacteeid  totalprice   Qty   Isactive

 checkbox                    25         1        1
 checkbox      2355          10         2        1
 checkbox      1234           8         1        1







在上面的gridview第一行transacteeid值为空。



当我跑上面的代码显示如下错误



无法将类型为system.DBNull的对象类型化为System.String。



错误显示如下以下





如何验证gridview行中的空值。



int.Parse((string)grdRpt.DataKeys [gvrow.RowIndex] .Value);



如何解决这个错误。



我有什么试过:



我的代码如下






in the above gridview first row transacteeid value is empty.

when i run the above code shows error as follows

unable to caste object of type system.DBNull to type System.String.

The error shows in below line as follows


how to validate empty value in gridview row.

int.Parse((string)grdRpt.DataKeys[gvrow.RowIndex].Value);

how to solve this error.

What I have tried:

My code as follows

private void SaveCheckedValues()
      {
          System.Collections.ArrayList userdetails = new System.Collections.ArrayList();
          int index = -1;
          foreach (GridViewRow gvrow in grdRpt.Rows)
          {
              int.Parse((string)grdRpt.DataKeys[gvrow.RowIndex].Value);

              bool result = ((CheckBox)gvrow.FindControl("chkselecdata")).Checked;

              // Check in the Session
              if (Session["CHECKED_ITEMS"] != null)
                  userdetails = (System.Collections.ArrayList)Session["CHECKED_ITEMS"];
              if (result)
              {
                  if (!userdetails.Contains(index))
                      userdetails.Add(index);
              }
              else
                  userdetails.Remove(index);
          }
          if (userdetails != null && userdetails.Count > 0)
              Session["CHECKED_ITEMS"] = userdetails;
      }



在gridview中如下




In gridview as follows

selectdata  transacteeid  totalprice   Qty   Isactive

 checkbox                    25         1        1
 checkbox      2355          10         2        1
 checkbox      1234           8         1        1







在上面的gridview第一行transacteeid值为空。



当我跑上面的代码显示如下错误



无法将类型为system.DBNull的对象类型化为System.String。



错误显示如下以下





如何验证gridview行中的空值。



int.Parse((string)grdRpt.DataKeys [gvrow.RowIndex] .Value);



如何解决这个错误。




in the above gridview first row transacteeid value is empty.

when i run the above code shows error as follows

unable to caste object of type system.DBNull to type System.String.

The error shows in below line as follows


how to validate empty value in gridview row.

int.Parse((string)grdRpt.DataKeys[gvrow.RowIndex].Value);

how to solve this error.

推荐答案

int.Parse()用于分配另一个变量的值解析后的值。



不使用下面的行,所以从代码中删除它: -

int.Parse() is used to assign the value of another variable after parse the value.

No use of below line, so remove it from your code: -
int.Parse((string)grdRpt.DataKeys[gvrow.RowIndex].Value);



删除此行后您的问题将得到解决。

也请检查此链接:Int32.Parse Method(String)(System) [ ^ ]


我相信你可能是存储



I believe You might be storing

int.Parse((string)grdRpt.DataKeys[gvrow.RowIndex].Value)





到自定义对象中。如果没有,那么你可以删除这一行。



如果你想用它作为支票那么





into a custom object. If not then you can remove this line.

and if you want to use it as a check then

if (available.Where(x => x.id == gvForCheckBox.DataKeys[gvrow.RowIndex].Value.ToString()).Any())


这篇关于如何使用分页gridview验证gridview中的空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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