Advertisement

06.26.2008 at 02:34PM PDT, ID: 23519947
[x]
Attachment Details

Use GridView controls for 2 gridviews

Asked by crundle in Programming for ASP.NET, .NET Framework 3.x versions

Need to have 2 gridviews on the same page and it may go up to four.  The subs now are only used on Gridview1 but, I need to used the subs for gridview2,3,4. I was thinking that maybe a function would work but, I cant figure it out. I have attached all code for review.Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
SUB's
Partial Class FormatHighPrices
    Inherits System.Web.UI.Page
    Protected Sub GridView1_RowCreated(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
        Dim Shipmentpref = "MBL|MBL,HBL|HBL,Sub BL|Sub_BL,Container #|ContainerNum,PO Number|PON,Container Size|Container_Type,Client Name|CLIENT_NAME,Shipper|Shipper_Name,Forwarding Agent|FA_Name,Consignee|Consignee_Name,Notify Party|Notify_Name,Broker|Broker,SSL Type of Move|SSLType_of_Move,Cust Type of Move|CUSTSSLType_of_Move,RailMove|Railmove,Carrier|Carrier,Vessel|Vessel_Airline,Voyage|Voyage_Flight,Point of Origin|POINT_OF_ORIGIN,POL|Port_of_Loading,POD|Port_of_Discharge,Rail Destination|Rail_destination,Place of delivery|Place_of_Delivery,IT Number|IT_Number,IT Number Date|IT_Number_Date,Firm code|FirmCode,Entered|EnteredDate,Entered By|EnteredBy,Last Update|LastUpdate,Lastupdate By|Lastupdateby,Sea Way BL|seawaybl"
        Shipmentpref = Shipmentpref.ToString.ToUpper
        Dim arrShipmentpref = Split(Shipmentpref, ",")
        Dim arrShipLabel As Array
        Dim Block As Int16 = 0
        e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#CFDBEF'")
        e.Row.Attributes.Add("ondblclick", "this.style.backgroundColor='#ECE9D8'")
        e.Row.Cells(1).Visible = False
        e.Row.Cells(2).Visible = False
        If e.Row.RowType = DataControlRowType.Header Then
            Dim c As TableCell
            Dim d As GridView = sender
            For Each c In e.Row.Cells
                For Each ArrayLabel In arrShipmentpref
                    arrShipLabel = Split(ArrayLabel, "|")
                    If d.AllowSorting Then
                        'If Block > 1 Then 'stop from fixing first column
                        Dim lb As System.Web.UI.WebControls.LinkButton
                        lb = CType(c.Controls(0), System.Web.UI.WebControls.LinkButton)
                        If arrShipLabel(1).ToString.ToString.ToUpper = lb.Text.ToUpper Then
                            lb.Text = arrShipLabel(0).ToString.ToUpper
                        Else
                            lb.Text = Replace(lb.Text.ToUpper, "_", " ")
                        End If
                        'End If
                        'Block = Block + 1 'stop from fixing first column
                    Else
                        If arrShipLabel(1).ToString.ToString.ToUpper = c.Text.ToUpper Then
                            c.Text = arrShipLabel(0).ToString.ToUpper
                        Else
                            c.Text = Replace(c.Text.ToUpper, "_", " ")
                        End If
                    End If
                Next
            Next
        End If
    End Sub
 
    Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
        Dim CellCount As Int16 = 0
        Dim CurDate As DateTime
        Dim HoldDate As Date
        Dim AdvDateDate As DateTime = DateTime.Now.AddDays(7)
 
        If GridView1.Rows.Count Then
            For Each cell As DataControlFieldCell In GridView1.Rows(0).Cells
                Dim cellColumn As DataControlField = cell.ContainingField
                If cellColumn.HeaderText.Trim.ToUpper.StartsWith("HOLD") Then
                    cellColumn.Visible = False
                    For j = 0 To GridView1.Rows.Count - 1
                        If IsDate(GridView1.Rows(j).Cells(CellCount - 1).Text) Then
                            If GridView1.Rows(j).Cells(CellCount).Text = 1 Then
                                GridView1.Rows(j).Cells(CellCount - 1).CssClass = "gvdateBL"
                            Else
                                If GridView1.Rows(j).Cells(CellCount - 1).Text > CurDate Then
                                    GridView1.Rows(j).Cells(CellCount - 1).CssClass = "gvdateRD"
                                ElseIf GridView1.Rows(j).Cells(CellCount - 1).Text < AdvDateDate Then
                                    GridView1.Rows(j).Cells(CellCount - 1).CssClass = "gvdateGR"
                                End If
                            End If
                            HoldDate = GridView1.Rows(j).Cells(CellCount - 1).Text
                            GridView1.Rows(j).Cells(CellCount - 1).Text = HoldDate.ToString("M/d/yyyy")
                        End If
                    Next
                End If
                CellCount = CellCount + 1
            Next
        End If
    End Sub
 
End Class
 
-------------------------------------------------
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="FormatHighPrices" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
 
    <title>Untitled Page</title>
    <link href="css/template.css" rel="stylesheet" type="text/css" />
 
<script language="javascript">
 
function gotopage(FLDName,valID,page){ 
//if (target_ == null){
//target_="_self";
//}
if (page != null){
alert('Test')
document.orderfrom.action = page;
}
document.orderfrom.getAttribute(FLDName).value = valID
//document.orderfrom.target = target_; 
document.orderfrom.submit();
}
</script>
</head>
<body>
    <form id="form1" runat="server" title="CLID">
         <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" CellPadding="5" AllowSorting="True" GridLines="Horizontal" BorderStyle="None" >
             <RowStyle BackColor="#ECE9D8" CssClass="BodyText"  />
             <Columns>
                 <asp:TemplateField HeaderText="CLID" SortExpression="CLID">
                    <ItemTemplate>
                    <a href="Javascript:gotopage('ShipmentID',<%# Eval("ShipmentID") %>)"><%# Eval("CLID") %></a>
                    </ItemTemplate>
                 </asp:TemplateField>                                        
             </Columns>
             <HeaderStyle CssClass="gvListHeaderRow" />
        </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:CLLDdataSQLConnectionString %>" 
        SelectCommand="test2" SelectCommandType="StoredProcedure" >
        <SelectParameters>
            <asp:Parameter DefaultValue="2" Name="ClientID" Type="Int32" />
            <asp:Parameter DefaultValue="container" Name="ShipmentType" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
 
         <asp:GridView ID="GridView2" runat="server" DataSourceID="SqlDataSource1" CellPadding="5" AllowSorting="True" GridLines="Horizontal" BorderStyle="None" >
             <RowStyle BackColor="#ECE9D8" CssClass="BodyText"  />
             <Columns>
                 <asp:TemplateField HeaderText="CLID" SortExpression="CLID">
                    <ItemTemplate>
                    <a href="Javascript:gotopage('ShipmentID',<%# Eval("ShipmentID") %>)"><%# Eval("CLID") %></a>
                    </ItemTemplate>
                 </asp:TemplateField>                                        
             </Columns>
             <HeaderStyle CssClass="gvListHeaderRow" />
        </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:CLLDdataSQLConnectionString %>" 
        SelectCommand="test2" SelectCommandType="StoredProcedure" >
        <SelectParameters>
            <asp:Parameter DefaultValue="2" Name="ClientID" Type="Int32" />
            <asp:Parameter DefaultValue="TRUCK" Name="ShipmentType" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
    </form>
 
</body>
</html>
[+][-]06.27.2008 at 08:35AM PDT, ID: 21884856

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]06.27.2008 at 09:04AM PDT, ID: 21885143

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Programming for ASP.NET, .NET Framework 3.x versions
Sign Up Now!
Solution Provided By: sammy1971
Participating Experts: 1
Solution Grade: A
 
 
[+][-]06.27.2008 at 07:24PM PDT, ID: 21888977

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628