Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
ShadingAnalysisDataSetTableAdapters.tbl_CadEngineersTeamTableAdapter cd;
cd = new ShadingAnalysisDataSetTableAdapters.tbl_CadEngineersTeamTableAdapter();
DataTable dt = new DataTable();
dt = cd.GetAvailableData(ddlCircle.SelectedValue); // Getting details of unassigned site

int x, y; //z;

DataTable dt3 = new DataTable();
dt3 = cd.GetTeam();
y = dt3.Rows.Count;

x = dt.Rows.Count; // counting the unassinged sites

DataTable dt2 = new DataTable();
dt2 = cd.GetAssignTeam(x);           //Getting team based on count

string[] arr = new string[dt2.Rows.Count];
int i = 0;
foreach (DataRow r in dt2.Rows)
  {
    arr[i] = r["Team"].ToString(); // assigning available team to array
    i++;
  }

   string[] strArr = new string[100]; // another array to copy arr values.

   i = 0; int j = 0;
   while (j <= x)
    {
     strArr[j]=  arr[i] ; // copying the arr[] values into strArr[] based on count.
     i++;
     j++;

     if (i == 3)
      {
        i = 0;
      }
   }

   GridView2.DataSource = strArr;
   GridView2.DataBind(); // error popup here
}
Posted

Hi,

The exception's first sentence tells it all "A data item was not found in the container"

Turns out that you have a null item in the list due to some filtering of data that you have included (transformation from array types to list type is involved).

Check for the null values in strArr

Regards,
Praneet
 
Share this answer
 
Now it is working and grid view control showing strArr values. Thank You.

C#
protected void ddlCircle_SelectedIndexChanged(object sender, EventArgs e)
{
    ShadingAnalysisDataSetTableAdapters.tbl_CadEngineersTeamTableAdapter cd;
    cd = new ShadingAnalysisDataSetTableAdapters.tbl_CadEngineersTeamTableAdapter();
    DataTable dt = new DataTable();
    dt = cd.GetAvailableData(ddlCircle.SelectedValue); // Getting details of unassigned site

    int x, y; //z;

    DataTable dt3 = new DataTable();
    dt3 = cd.GetTeam();
    y = dt3.Rows.Count;

    x = dt.Rows.Count; // counting the unassinged sites

    DataTable dt2 = new DataTable();
    dt2 = cd.GetAssignTeam(x);           //Getting team based on count

    string[] arr = new string[dt2.Rows.Count];
    int i = 0;
    foreach (DataRow r in dt2.Rows)
    {
        arr[i] = r["Team"].ToString(); // assigning available team to array
        i++;
    }

    string[] strArr = new string[x+1]; // another array to copy arr values.

    i = 0; int j = 0;
    while (j <= x)
    {
        strArr[j]=  arr[i] ; // copying the arr[] values into strArr[] based on count.
        i++;
        j++;

        if (i == 3)
        {
            i = 0;
        }
    }

    GridView2.DataSource = strArr;
    GridView2.DataBind(); 
}
 
Share this answer
 

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