• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 260
  • Last Modified:

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
0
jpetter
Asked:
jpetter
  • 3
  • 3
1 Solution
 
tusharashahCommented:
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
0
 
jpetterAuthor Commented:
tushar,

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

Jeff
0
 
jpetterAuthor Commented:
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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
tusharashahCommented:
I am not getting what you want to achieve here clearly...

"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). "

Also, ItemDataBound event is called on each Row of DataGrid seperatly... so I think you do not need For loop in your ItemDataBound event...

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
        Dim counter As Integer
            Select Case e.Item.ItemType
                Case ListItemType.Item, ListItemType.AlternatingItem
                    e.Item.Cells(e.Item.ItemIndex).Text = SummaryArray(e.Item.ItemIndex)
            End Select
End Sub

Also.... if in any case wat you really need is only Summary of DataGrid Rows in Footer you can try this:

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.Footer     ' <---- Make sure Footer is Enabled for DataGrid here..
                    e.Item.Cells(counter).Text = SummaryArray(counter)
                    'Case ListItemType.AlternatingItem
                    '   e.Item.Cells(counter).Text = SummaryArray(counter)
            End Select
        Next

    End Sub

-tushar
0
 
jpetterAuthor Commented:
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
0
 
tusharashahCommented:
Nice to have you going Jeff.. :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now