gridview hide column from the code behind

newbie27 used Ask the Experts™
hello epxerts
i am trying to add a hyperlink column to the gridivew and hide the default custid column which is pullying the database

 <asp:gridview ID="grdCustomers" runat="server">
            <asp:TemplateField HeaderText="Customer ID" InsertVisible="False" SortExpression="CustID">
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("CustID") %>'></asp:Label>
                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "UpdateCustomer.aspx?CID=" & Eval("CustID") %>'
                        Text='<%# Eval("CustID") %>'></asp:HyperLink>
              <asp:BoundField DataField="CustID" HeaderText=""
                SortExpression="CustID" />

i am geting this error

error BC30311: Value of type 'System.Web.UI.WebControls.BoundColumn' cannot be converted to 'System.Web.UI.WebControls.DataControlField'.

>> grdCustomers.Columns.Add(objbc)

please can you adivse?

Dim dbconn As SqlConnection
        Dim dbcomm As SqlCommand
        Dim ds As DataSet
        Dim myAdap As SqlDataAdapter

        dbconn = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("CString").ConnectionString)

        dbcomm = New SqlCommand("GetCustomerDetails", dbconn)

        ds = New DataSet()
        myAdap.Fill(ds, "TempTable")

        Dim i As Integer
        For i = 0 To ds.Tables(0).Columns.Count - 1

            Dim objbc As New BoundColumn()
            objbc.DataField = ds.Tables(0).Columns(i).ColumnName
            objbc.HeaderText = ds.Tables(0).Columns(i).ColumnName

            If objbc.DataField = ds.Tables(0).Columns("CustId").ColumnName Then
                objbc.Visible = False
            End If

            grdCustomers.DataSource = ds.Tables(0)
        ' grdCustomers.DataSource = dbcomm.ExecuteReader()



Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial