Solved

Need to display an unbound checkbox for each record in gridview

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

Independent Software Vendors: 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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
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.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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