Advertisement

05.09.2008 at 01:55PM PDT, ID: 23390815
[x]
Attachment Details

Remove column from gridview

Asked by crundle in Programming for ASP.NET, Microsoft Visual Basic.Net, .NET Framework 2.x

Have the below code that should remove columns from a grideview, however it only works when I try pulling that data from a excel spread sheets and not when I pull for my MS SQL database. For some reason it can not get a count of the columns. Any ideas where I'm going wrong?

On a side question how do you set the cell format for a date (DD/MM/YYYY)?
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:
<%@ 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="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
            <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="GridView1" runat="server" AutoGenerateColumns DataSourceID="SqlDataSource1" 
            AllowSorting="True">
        </asp:GridView>
   <%TextBox1.Text = GridView1.Columns.Count%>
        
        
    </div>
    </form>
</body>
</html>
 
 
--------------------------------------------------------------------
 
Partial Class FormatHighPrices
    Inherits System.Web.UI.Page
 --------------------------------------------------------------------
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            For j = 0 To e.Row.Cells.Count - 1
                If IsNumeric(e.Row.Cells(j).Text) Then
                    If e.Row.Cells(j).Text = 1 Then
                    e.Row.Cells(j - 1).BackColor = System.Drawing.Color.Maroon
                    End If
                End If
            Next
        End If
    End Sub
--------------------------------------------------------------------
    Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound
       For i As Integer = 0 To Me.GridView1.Columns.Count - 1
            If Me.GridView1.Columns(i).HeaderText.Trim.ToUpper.StartsWith("HOLD") Then
                Me.GridView1.Columns(i).Visible = False
            End If
        Next
    End Sub
End Class
[+][-]05.09.2008 at 03:28PM PDT, ID: 21536772

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.

 
[+][-]05.09.2008 at 05:43PM PDT, ID: 21537360

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

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

 
[+][-]05.10.2008 at 04:23AM PDT, ID: 21538517

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, Microsoft Visual Basic.Net, .NET Framework 2.x
Sign Up Now!
Solution Provided By: DarkoLord
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.10.2008 at 02:08PM PDT, ID: 21540485

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

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

 
[+][-]05.10.2008 at 02:13PM PDT, ID: 21540491

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