Solved

Need to display an unbound checkbox for each record in gridview

Posted on 2006-07-02
4
1,488 Views
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)

        dataadapterSubjectCompetitors.GetFillParameters()
       
        dataadapterSubjectCompetitors.Fill(datatableSubjectCompetitors)
       
        intRows = datatableSubjectCompetitors.Rows.Count
       
        With gridviewSubjectCompetitors
            If intRows > 0 Then
                '.EnableSortingAndPagingCallbacks = False
                .DataSource = datatableSubjectCompetitors
                .DataBind()
                .Visible = True
            Else
                .Visible = False
            End If
        End With

    End Sub
0
Comment
Question by:psk1
  • 3
4 Comments
 
LVL 12

Accepted Solution

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

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

to display a checkbox without binding it
maybe
http://www.gridviewguy.com/ArticleDetails.aspx?articleID=178
0
 
LVL 2

Author Comment

by:psk1
ID: 17028560
Within the gridview I have:

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

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

Author Comment

by:psk1
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>
 
0
 
LVL 2

Author Comment

by:psk1
ID: 17031212
The link you posted did the trick:

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

Thanks!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now