Click here to Skip to main content
13,193,650 members (59,644 online)
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 12-Jun-14 21:34pm
Updated 12-Jun-14 22:00pm
v2
Rate this: bad
 
good
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
  Permalink  
Rate this: bad
 
good
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;
}
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web01 | 2.8.171018.2 | Last Updated 4 Nov 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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