GridView Checkbox Column

Last post 04-18-2008 6:31 AM by ashrafur. 3 replies.

Sort Posts:

  • GridView Checkbox Column

    07-30-2007, 11:54 AM
    • Loading...
    • bafadam
    • Joined on 02-05-2007, 10:15 PM
    • Posts 9

    I've got a GridView that I want to put a checkbox column into.  The GridView is already databound to three text fields.  I want to add the checkbox column as an unbound column.  When I try and add it through the designer (Edit Columns...) I can add any column I want - except that one.  When I select it in the treeview, the option to add grays out.

    If I "Add New Column..." from the GridView menu or I manually put in the <asp:CheckBoxColumn...> tag, the column itself appears just fine, except the checkbox isn't there!  When I preview in the browser, the checkbox isn't there, either!

     I'm sure this is something really simple.  Can anyone point me in the right direction?

    Filed under: ,
  • Re: GridView Checkbox Column

    07-30-2007, 11:59 AM
    Answer
    • Loading...
    • triggered
    • Joined on 05-30-2007, 2:10 PM
    • Posts 682

     <TemplateField>
       <ItemTemplate>

               <asp:CheckBox ID="chk" runat="server" Text="Check Me" />
     

      </ItemTemplate> 
    </TemplateField> 

     

    If you want the other columns to be bound just show which ones by adding another TemplateField

     <TemplateField>
       <ItemTemplate>

              <asp:Literal ID="lTitle" runat="server" Text='<%# Eval("title") %>' />

     

      </ItemTemplate> 
    </TemplateField>

     Where Title is a property from your bounded object

  • Re: GridView Checkbox Column

    04-18-2008, 3:33 AM
    • Loading...
    • smoothmovz
    • Joined on 04-17-2008, 8:56 AM
    • Philippines
    • Posts 34

    what if, i want to add a check box in my last row??

    my code:

                    Dim Col1 As New BoundField 
                    Dim Col2 As New CheckBoxField

                    GridView1.Columns.Clear()

                    GridView1.Columns.Add(Col1)
                    Col1.DataField = "Name"
                    Col1.HeaderText = "ID"
                    Col1.Visible = False

                    GridView1.Columns.Add(Col2)
                    ?
                    ?
                    ?

                    GridView1.DataSource = myDataTable
                    GridView1.DataBind()

     what should be my codes in the ? part?

    Filed under: , ,
  • Re: GridView Checkbox Column

    04-18-2008, 6:31 AM
    • Loading...
    • ashrafur
    • Joined on 04-15-2008, 3:14 AM
    • Dhaka, Bangladesh
    • Posts 72

    Hi, Please go this link http://www.codeproject.com/KB/webforms/Editable_GridView.aspx

    Here is a complete Editable GridView loaded with  textbox, dropdownlist and checkbox. hope that this will may help you.

    Ashrafur Rahaman
    http://www.ashrafur.com
Page 1 of 1 (4 items)
Microsoft Communities
Page view counter