Link to home
Start Free TrialLog in
Avatar of jpetter
jpetter

asked on

Is there a way to bind columns of a DataGrid to different datasources?

I have to display a summary report on our intranet. Since I used the DataGrid for the other reports I've created, I thought I could possibly use it for this as well. However, I really don't know if what I need to do can be done using the DataGrid. Each column in the grid would need to display a heading and number from a seperate query. So, I would think that I would then need to create a dataset for each query, and bind the successive, individual columns to the different datasets.

Does anyone know if this can be done, and if so, help me along in the right direction?

Thanks,
Jeff
Avatar of tusharashah
tusharashah

Keep that particular Column blank and feel it in OnItemDataBound event of your DataGrid:

// lets say you want to Feel Column 0 of your DataGrid based upon some value of Column 1...
// run your query on GetData(..) function and return result as String
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
      switch( e.Item.ItemType )
      {
            case ListItemType.Item:
            case ListItemType.AlternatingItem:
                   e.Item.Cells[0].Text = GetDataFunction( e.Item.Cells[0].Text );
            break;
      }
}


-tushar
Avatar of jpetter

ASKER

tushar,

Thanks. Let me give it a try and I'll get back. Thx.

Jeff
Avatar of jpetter

ASKER

tushar,

I think I have it so that it just about works the way I want it to. Thanks.

I do find something strange that I have so far not been able to figure out. Though I should only display one row, which is the summary information, I am displaying eleven rows (or six if I rem out the AlternatingItem). Would have any idea what could be causing that? I've pasted the ItemDataBound event below.

Thanks,
Jeff

    Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
        Dim counter As Integer

        For counter = 0 To 9
            Select Case e.Item.ItemType
                Case ListItemType.Item
                    e.Item.Cells(counter).Text = SummaryArray(counter)
                    'Case ListItemType.AlternatingItem
                    '   e.Item.Cells(counter).Text = SummaryArray(counter)
            End Select
        Next

    End Sub
ASKER CERTIFIED SOLUTION
Avatar of tusharashah
tusharashah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jpetter

ASKER

tushar,

That last code snippet with the footer did it. Sorry I didn't make myself more clear. I had misunderstood the way the event fired, and was looping in hopes of populating the proper cell with the proper element from the array.

Thanks again for your help,
Jeff
Nice to have you going Jeff.. :)