Click here to Skip to main content
15,909,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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

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


1) Debug your code
2) Check is there any rows in your table DBCUSTOMERMASTER
 
Share this answer
 
Update your code as:


HTML
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;
}
 
Share this answer
 
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, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900