Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4265944
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:41:34+00:00 2026-05-21T06:41:34+00:00

I am creating a gridview programmatically and I want to use the solution to

  • 0

I am creating a gridview programmatically and I want to use the solution to this question: Programmatically access GridView columns and manipulate. In other words, I want to hide the hyperlinkfield and instead display a templatefield if the value of the “submitted” column in the row is 1. I’m listing employment applications and letting the user click “Load Application” if they have not yet submitted an application, or displaying “submitted” in plain text if they have already submitted it. I know how to do this if I create my gridview in the aspx file, but I don’t know how to do this when I’m creating my gridview at runtime. Here’s my code:

Public Sub getSavedApps(ByVal userID As Integer)
        Dim ds As New DataSet
        ds = clsData.sqlGetAllApps(userID)
        If ds.Tables(0).Rows.Count > 0 Then
            popAppSelect.Show()

            'let user select which app they want to work on
            Dim grdAppSelect As New GridView

            'need to find out if this row has a value of 1 or 0 for submitted
            Dim submitted As Boolean

            'position column
            Dim fieldPosition As New BoundField
            fieldPosition.DataField = "positionDesired"
            fieldPosition.HeaderText = "Position Desired"
            If fieldPosition.DataField.ToString = "" Then
                fieldPosition.DataFormatString = "<em>No position specified</em>"
            End If
            Dim colPosition As DataControlField = fieldPosition

            'date column
            Dim fieldDate As New BoundField
            fieldDate.DataField = "dateStarted"
            fieldDate.HeaderText = "Date Started"
            Dim colDate As DataControlField = fieldDate

            Dim strAppID(0) As String
            strAppID(0) = "appID"
            Dim colLoad As DataControlField

            'submitted column
            If submitted Then
                Dim fieldLoad As New TemplateField
                fieldLoad.ItemTemplate = New GridViewTemplate(DataControlRowType.DataRow, "submitted")
                colLoad = fieldLoad
            Else
                Dim fieldLoad As New HyperLinkField
                fieldLoad.Text = "<b>Load Application &raquo;</b>"
                fieldLoad.DataTextFormatString = "{0}"
                fieldLoad.DataNavigateUrlFields = strAppID
                fieldLoad.DataNavigateUrlFormatString = "?load={0}"
                colLoad = fieldLoad
            End If

            'add the columns to the gridview
            With grdAppSelect
                .ID = "grdAppSelect"
                .CssClass = "grdAppSelect"
                .CellPadding = 5
                .BorderWidth = "0"
                .HeaderStyle.HorizontalAlign = HorizontalAlign.Left
                With .Columns
                    .Add(colPosition)
                    .Add(colDate)
                    .Add(colLoad)
                End With
                .AutoGenerateColumns = False
                .DataSource = ds.Tables(0)
                .DataBind()
            End With

            Dim lnkNew As New HyperLink
            lnkNew.Text = "<b>Start New Application &raquo;</b>"
            lnkNew.NavigateUrl = "?load="

            Dim strClear As New LiteralControl
            strClear.Text = "<br class='clearer' />"

            'add the controls to the panel
            pnlAppSelect.Controls.Add(grdAppSelect)
            pnlAppSelect.Controls.Add(strClear)
            'pnlAppSelect.Controls.Add(lnkNew)

        Else
            'should be apps there but couldn't find them
            lblGeneralError.Text = "Could not find any previously started applications."
        End If
    End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:41:35+00:00Added an answer on May 21, 2026 at 6:41 am

    I found the solution. I needed to add an event handler when I created the gridview so that I could access the RowDataBound event and do the evaluation there. Here’s the event handler code I used:

    AddHandler grdAppSelect.RowDataBound, AddressOf grdAppSelect_RowDataBound
    

    Then I just did my evaluation during RowDataBound like so:

    Sub grdAppSelect_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    
        If e.Row.RowType = DataControlRowType.DataRow Then
    
            Dim load As Control = e.Row.Controls(2)
            Dim submitted As Control = e.Row.Controls(3)
            Dim submittedText As String = e.Row.Cells(3).Text
            If submittedText = "True" Then
                load.Visible = False
            End If
            submitted.Visible = False
    
        End If
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(creating a separate question after comments on this: Javascript redeclared global variable overrides old
I creating LinearLayout programatically then I want to attach it to GridView via custom
This is my first real question of need for any of those Gridview experts
I have an ASP.NET GridView which has columns that look like this: | Foo
I'm creating a custom ASP.Net GridView and I want to be able to alter
I'm creating a custom view derived from GridView. This contains a custom ImageView with
I am creating a dropdown list in code for a gridview. I want to
I am creating a simple app for my own use. I want to have
Hellow this is my first question in stack. Im creating a dynamic grid of
I'm creating a gridview dynamically based on number of users selected but want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.