Need to display an unbound checkbox for each record in gridview

Posted on 2006-07-02
Medium Priority
Last Modified: 2011-09-20
Using VWD Express, ASP.NET 2.0, VB.  I have a gridview on my web form.  In the Columns collection, I have identified one unbound checkbox field and several databound fields.  I use the below code to populate the gridview dynamically.

The unbound field does not appear (in design or browser views) with a checkbox.  The idea is to have several unbound checkboxes that would auto-postback onclick, and allow the codebehind to build an array of selections (using the non-visible ID field from the gridview).

How can I display and use an unbound checkbox for each row in the gridview?

    Protected Sub doPopulateGridviewSubjectCompetitors(Optional ByVal strOrderByFieldName As String = "SubjectID")
        Dim datatableSubjectCompetitors As New DataTable("datatableSubjectCompetitors")

        Dim intRows As Integer
        Dim strSql As String
        Dim objConn As OleDb.OleDbConnection
        Dim objCmd As OleDb.OleDbCommand
        objConn = New OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings.Item("connFloratrak").ConnectionString)

        strSql = "PARAMETERS subjRad Long, subjLat IEEEDouble, subjLng IEEEDouble; SELECT Subjects.SubjectID, Subjects.BusinessName, Subjects.City, Subjects.StateCode FROM (Subjects) WHERE (((Subjects.Zip) In (SELECT Zip FROM ZipCodes WHERE [subjRad] > 3959 * ATN( SQR(1 - (SIN([subjLat]/ 57.3) * SIN(LAT/ 57.3) + COS([subjLat]/ 57.3) * COS(LAT/ 57.3) * COS((LNG/ 57.3) - ([subjLng]/ 57.3))) ^2 ) / (SIN([subjLat]/ 57.3) * SIN(LAT/ 57.3) + COS([subjLat]/ 57.3) * COS(LAT/ 57.3) * COS((LNG/ 57.3) - ([subjLng]/ 57.3))) ) )))"
        strSql &= " ORDER BY " & strOrderByFieldName
        objCmd = New OleDbCommand(strSql, objConn)
        setParam(objCmd, "subjRad", OleDbType.BigInt, CLng(vRad.Text))
        setParam(objCmd, "subjLat", OleDbType.Double, CDbl(vLat.Text))
        setParam(objCmd, "subjLng", OleDbType.Double, CDbl(vLng.Text))
        Dim dataadapterSubjectCompetitors As New OleDbDataAdapter(objCmd)

        intRows = datatableSubjectCompetitors.Rows.Count
        With gridviewSubjectCompetitors
            If intRows > 0 Then
                '.EnableSortingAndPagingCallbacks = False
                .DataSource = datatableSubjectCompetitors
                .Visible = True
                .Visible = False
            End If
        End With

    End Sub
Question by:psk1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 12

Accepted Solution

deanvanrooyen earned 2000 total points
ID: 17028288
I am not realy sure what you are asking -            

to display a checkbox
                          <asp:CheckBox ID="chkbox" runat="server" Text='<%# System.Convert.ToBoolean(Eval("BoolDataField")) %>' Checked='<%# System.Convert.ToBoolean(Eval("BoolDataField")) %>' />

to display a checkbox without binding it

Author Comment

ID: 17028560
Within the gridview I have:

                            <asp:CheckBoxField HeaderText="Select">
                                <ItemStyle Width="50px" />

I'll try using the template tags for the field.. and I'll check out your link.

Author Comment

ID: 17031190
DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'BoolDataField'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'BoolDataField'.

Source Error:

Line 423:                        <asp:TemplateField>
Line 424:                             <ItemTemplate>
Line 425:                                  <asp:CheckBox ID="chkbox" runat="server" Text='<%# System.Convert.ToBoolean(Eval("BoolDataField")) %>' Checked='<%# System.Convert.ToBoolean(Eval("BoolDataField")) %>' />
Line 426:                             </ItemTemplate>
Line 427:                        </asp:TemplateField>

Author Comment

ID: 17031212
The link you posted did the trick:

<asp:TemplateField  HeaderText="Select">
<asp:CheckBox ID="chkSelect" runat="server" />


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question