Click here to Skip to main content
14,218,748 members
Rate this:
Please Sign up or sign in to vote.
See more:
string str = "Select * from DBCUSTOMERMASTER ";
         
                             
            DataTable dt = clstrans.getDataTable(str);

             

            grdTRANSANCTION.DataSource = dt;
            grdTRANSANCTION.DataBind();
            for (int i = 0; i <grdtransanction.rows.count;>            {
                string str2 = "select STATEMENTMENTDELIVERD  from TBLTRANSACTIONMASTER where CUSTOMERID='" + grdTRANSANCTION.Rows[i].Cells[0].Text+ "' and MONTH='" + DdlMonth.SelectedItem.Text + "' and YEAR ='" + DDLYEAR.SelectedItem.Text + "'";
              
                DataTable dt2 = clstrans.getDataTable(str2);
                CheckBox chk = (CheckBox)grdTRANSANCTION.Rows[i].FindControl("CHKPAYMENT");
                string str1 = dt2.Rows[i]["STATEMENTMENTDELIVERD"].ToString();
                if (str1 == "yes")
                {
                   
                    chk.Checked = true;

                }
                else
                {
                    chk.Checked = false;
                }


            }
            
          
         

        }
        catch (Exception ex)
        {
            lblmessage.Text = ex.Message;
        }
Posted
Updated 12-Jun-14 22:00pm
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

your datatable doesn't contains any Rows in it, thats why that error occurs,
to prevent it always use condition to check like that
if(dt.Rows.Count>0)
{
//Do youe Stuff
}


1) Debug your code
2) Check is there any rows in your table DBCUSTOMERMASTER
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Update your code as:


string str = "Select * from DBCUSTOMERMASTER ";
DataTable dt = clstrans.getDataTable(str);
grdTRANSANCTION.DataSource = dt;
grdTRANSANCTION.DataBind();

if(dt.rows.count>0)
{
  for (int i = 0; i<grdtransanction.rows.count;i++)>
{
string str2 = "select STATEMENTMENTDELIVERD from TBLTRANSACTIONMASTER where CUSTOMERID='" + grdTRANSANCTION.Rows[i].Cells[0].Text+ "' and MONTH='" + DdlMonth.SelectedItem.Text + "' and YEAR ='" + DDLYEAR.SelectedItem.Text + "'";

DataTable dt2 = clstrans.getDataTable(str2);
CheckBox chk = (CheckBox)grdTRANSANCTION.Rows[i].FindControl("CHKPAYMENT");
string str1 = dt2.Rows[i]["STATEMENTMENTDELIVERD"].ToString();
  if (str1 == "yes")
    {
     chk.Checked = true;
    }
  else
    {
     chk.Checked = false;
    }
 }
}
}
catch (Exception ex)
{
lblmessage.Text = ex.Message;
}
   
v2
Comments
suraj Repe 13-Jun-14 5:03am
   
hello sir i use above but it gives same error ,for (int i = 0; i<grdtransanction.rows.count;i++)> wether this statement valid ..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100