views:

18

answers:

1

I am binding the data in a data table from two different datagrid

protected ICollection BindGenerateReport()
    {
        DataTable dtGenerateReport = new DataTable();
        DataRow drRow;
        for (int innerCounter = 0; innerCounter < dgInvoices.Columns.Count; innerCounter++)
        {
            dtGenerateReport.Columns.Add();
        }
        for (int counter = 0; counter < dgInvoices.Items.Count+dgReceipts.Items.Count;counter++ )
        {
            drRow = dtGenerateReport.NewRow();
            if (dgReceipts.Columns[6] == dgInvoices.Columns[1])
            {
                for (int innerCounter = 0; innerCounter < dgReceipts.Columns.Count; innerCounter++)
                {
                    drRow[innerCounter] = dgReceipts.Columns[innerCounter];
                }
            }
            else
            {
                for (int innerCounter = 0; innerCounter < dgInvoices.Columns.Count; innerCounter++)
                {
                    drRow[innerCounter] = dgInvoices.Columns[innerCounter];
                }
            }
           dtGenerateReport.Rows.Add(drRow);
        }

        DataView dv = new DataView(dtGenerateReport);
        return dv;
    }

and i am binind the function a event click like that

 protected void btnGenerateReport_Click(object sender, EventArgs e)
    {

        dgGenerateReport.DataSource = BindGenerateReport();
        dgGenerateReport.DataBind();
    }

but i want to know that what exactlu datagrid.columns[number] returns (the value inside that column or the datatype or only the column collection ).My code is not working

+2  A: 

The columns collection will return an instance of a type derived from DataGridColumn, this could be a BoundColumn, ButtonColumn etc.

Check the MSDN Article for more information.

Matthew Abbott
(dgReceipts.Columns[6] == dgInvoices.Columns[1])what it compares value of column[6] with column[1]or something else
subodh
No, that will compare two instances of DataGridColumn, which I don't think are comparable. You need to be comparing the row values..
Matthew Abbott