Как проверить нулевое значение gridview
Мой код выглядит следующим образом
частный недействительными SaveCheckedValues()
{
Система.Коллекции.Userdetails коллекции = новый
Система.Коллекции.список ArrayList();
индекс int = -1;
по каждому элементу (gvrow GridViewRow в grdRpt.Строк)
{
индекс = конвертировать.ToInt32(grdRpt.DataKeys[gvrow.Параметр rowindex].Значение);
bool result = ((CheckBox)gvrow.FindControl("chkselecdata")).Checked; 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; } when i run the above code shows error as follows Object cannot be cast from DBNull to other types. The error shows in below line as follows index = Convert.ToInt32(grdRpt.DataKeys[gvrow.RowIndex].Value); In the gridview as follows selectdata transacteeid Qty Price Isactive checkbox 6 25 1 checkbox 4 20 1 checkbox 109453628727 1 8 1 checkbox 109453628727 2 6 1 checkbox 109453628727 3 7 1 checkbox 109453628727 5 2 1 checkbox 109453628727 1 5 1 how to fix this error. in the gridview first two rows values is empty. because of this shows error. i think. how to validate this null value in the gridview. 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) { index = Convert.ToInt32(grdRpt.DataKeys[gvrow.RowIndex].Value); <pre> bool result = ((CheckBox)gvrow.FindControl("chkselecdata")).Checked; 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; } when i run the above code shows error as follows Object cannot be cast from DBNull to other types. The error shows in below line as follows index = Convert.ToInt32(grdRpt.DataKeys[gvrow.RowIndex].Value); In the gridview as follows selectdata transacteeid Qty Price Isactive checkbox 6 25 1 checkbox 4 20 1 checkbox 109453628727 1 8 1 checkbox 109453628727 2 6 1 checkbox 109453628727 3 7 1 checkbox 109453628727 5 2 1 checkbox 109453628727 1 5 1 how to fix this error. in the gridview first two rows values is empty. because of this shows error. i think. how to validate this null value in the gridview.