Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can I format two grids using the same GridItem?
Message
 
 
To
All
General information
Forum:
ASP.NET
Category:
Forms
Title:
Can I format two grids using the same GridItem?
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01401161
Message ID:
01401161
Views:
71
Hi everybody,

I have two DataGrids that should be bound to different data tables, but use the same formatting. I tried to generalize the code this way:
#region Format Order Details Grid (View page & New Order page)
        private void FormatOrderDetailsGrid(OrderDetailsDS.OrderDetailsDataTable dt, DataGrid gr)
        {
            if (_gridStyleItem == null)
            {
                _gridStyleItem = new DataGridTableStyle();

                gr.TableStyles.Add(_gridStyleItem);
                gr.TableStyles[0].MappingName = dt.TableName;
                //this.Width = 220;
                //this.grdOrderItems.Width = 220;

                //Order No column               

                //Order Item Column
                DataGridTextBoxColumn colManPartNo = new DataGridTextBoxColumn();
                //colManPartNo.Owner = this.grdOrderItems;
                colManPartNo.HeaderText = "Item No";
                colManPartNo.MappingName = "ItemNo";
                colManPartNo.Width = ((gr.Width * 20) / 100);
                //colManPartNo.Alignment = HorizontalAlignment.Left;

                // Unfortunately the Description column is not in OrderDetails table
                //Order Item Description
                DataGridTextBoxColumn colDescription = new DataGridTextBoxColumn();
                //colDescription.Owner = this.grdOrderItems;
                colDescription.HeaderText = "Description";
                colDescription.MappingName = "Description";
                colDescription.Width = ((gr.Width * 40) / 100);
                //colDescription.Alignment = HorizontalAlignment.Left;

                DataGridTextBoxColumn colQuantity = new DataGridTextBoxColumn();
                //colQuantity.Owner = this.grdOrderItems;
                colQuantity.HeaderText = "Qty";
                colQuantity.MappingName = "Qty";
                colQuantity.Width = ((gr.Width * 10) / 100);
                //colQuantity.Alignment = HorizontalAlignment.Center;

                //Order Item Price
                DataGridTextBoxColumn colPrice = new DataGridTextBoxColumn();
                //colPrice.Owner = this.grdOrderItems;
                colPrice.HeaderText = "Price";
                colPrice.MappingName = "Price";
                colPrice.Width = ((gr.Width * 15) / 100);
                //colPrice.Alignment = HorizontalAlignment.Right;
                // Setup table mapping name

                //Order Item Total Price
                DataGridTextBoxColumn colTotalPrice = new DataGridTextBoxColumn();
                //colTotalPrice.Owner = this.grdOrderItems;
                colTotalPrice.HeaderText = "Total";
                colTotalPrice.MappingName = "TotalPrice";
                colTotalPrice.Width = ((gr.Width * 15) / 100);
                //colTotalPrice.Alignment = HorizontalAlignment.Right;

                // Setup table mapping name
                gr.TableStyles[0].GridColumnStyles.Add(colManPartNo);
                gr.TableStyles[0].GridColumnStyles.Add(colDescription);
                gr.TableStyles[0].GridColumnStyles.Add(colQuantity);
                gr.TableStyles[0].GridColumnStyles.Add(colPrice);
                gr.TableStyles[0].GridColumnStyles.Add(colTotalPrice);
                gr.RowHeadersVisible = false;

                gr.DataSource = dt;
                gr.Refresh();
            }
        }
Unfortunately, obviously it only formats the first grid and not the second. How can I made this code generic enough to call multiple times?

Thanks a lot in advance.
If it's not broken, fix it until it is.


My Blog
Next
Reply
Map
View

Click here to load this message in the networking platform