Solved

Need to display an unbound checkbox for each record in gridview

Posted on 2006-07-02
4
1,493 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
[X]
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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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