How to add a checkbox in Gridview ???

Last post 04-27-2008 11:28 AM by abhilashca. 7 replies.

Sort Posts:

  • How to add a checkbox in Gridview ???

    06-22-2007, 12:13 AM
    • Member
      92 point Member
    • enghsiang
    • Member since 06-14-2007, 5:03 AM
    • Malaysia
    • Posts 236

    Can someone please teach me how to add a checkbox in gridview?

    i added from the add new columns,but the checkbox is not fuctioning when i run my page,means it can't be check

    can someone please teach me in detail?coz i am new in ASP.Net 2.0 ( Using Visual Studio 2005)

    and if possible,i wan to retrieve 1 of the column value of the database row which being checked

    can someone teach me this as well?

    thanksSmile

    C#######################################
  • Re: How to add a checkbox in Gridview ???

    06-22-2007, 1:07 AM
    • Participant
      850 point Participant
    • zaladane
    • Member since 06-19-2007, 6:44 AM
    • California
    • Posts 194

    Hello,

    Maybe this article could help you, since the steps are a little bit too complex to explain in a few lines: http://support.microsoft.com/kb/306227

    Hope it helps

    Still in search of the far side.
    --------------------------------
    A code snippet may help you, but a reference to the doc will teach you something for later...Don't just try to solve somebody's problem with a snippet, teach him how to solve it.
  • Re: How to add a checkbox in Gridview ???

    06-22-2007, 2:48 AM
    Answer
    • Member
      172 point Member
    • wreck_of_u
    • Member since 11-07-2006, 4:55 AM
    • Posts 84

    Hi,

    you can use TemplateFields for the GridView:

                     <asp:GridView ID="GridView1" runat="server">

                       <Columns>

                            <asp:TemplateField >
                                <ItemTemplate>
                                    <asp:CheckBox ID="myCheckBox" runat="server" />
                                </ItemTemplate>
                            </asp:TemplateField>

                      </Columns>

                   </asp:GridView>

     

    Hope this helps:)

  • Re: How to add a checkbox in Gridview ???

    06-22-2007, 3:07 AM
    • Member
      92 point Member
    • enghsiang
    • Member since 06-14-2007, 5:03 AM
    • Malaysia
    • Posts 236

    Thanks both of u

    i already solve my problem.

    but still facing another problem.i wish to get the data from the gridview row which being checked

    i already open a post which pending for approval.hope u both still can give me some idea.thanksSmile

    C#######################################
  • Re: How to add a checkbox in Gridview ???

    06-22-2007, 3:18 AM
    • Member
      172 point Member
    • wreck_of_u
    • Member since 11-07-2006, 4:55 AM
    • Posts 84

    You may want to convert everything in your GridView into TemplateFields,

    after that, you will need to FindControl each of those TemplateField controls in the GridView. Finding a control in a GridView is like this:

    Dim myLabel As New Label
    ClusterName = GV.Rows(1).Cells(2).FindControl("myLabelinTheGridViewTemplateField")

     

     Ill wait for your pending post, then ill discuss further over there :)

     

    Cheers

  • Re: How to add a checkbox in Gridview ???

    06-22-2007, 3:29 AM
    • Member
      92 point Member
    • enghsiang
    • Member since 06-14-2007, 5:03 AM
    • Malaysia
    • Posts 236

    Convert everything into TempleteFields? how to do that?can u tell me detail about that?

    this is the post  http://forums.asp.net/t/1125079.aspx

    thanks for helping Smile

    C#######################################
  • Re: How to add a checkbox in Gridview ???

    06-22-2007, 11:08 AM
    • Participant
      850 point Participant
    • zaladane
    • Member since 06-19-2007, 6:44 AM
    • California
    • Posts 194

    I generally always use templateFields too since i generally don't want things to be line up in columns.

    1-in the smart Gridview Tasks that pops open when you drop a gridview on the form , Click on Edit Columns.

    2- In the listbox on the top left side , click on TemplateField and push the add button. The field is added to the bottom left list.

    3- you can set a couple of the field properties in the right side  (the Header text might be a good start.)

    4- When you hit ok, the popup is still open, click on Edit Templates... and customize your ItemTemplate. (depending on what you want the EditItemTemplate and the ItemTemplate to look like ).

     

    Still in search of the far side.
    --------------------------------
    A code snippet may help you, but a reference to the doc will teach you something for later...Don't just try to solve somebody's problem with a snippet, teach him how to solve it.
  • Re: How to add a checkbox in Gridview ???

    04-27-2008, 11:28 AM
    • Participant
      1,169 point Participant
    • abhilashca
    • Member since 02-29-2008, 5:01 AM
    • India
    • Posts 248

    Pickick a GridView, Connect it to a table.

    - Go to the 'Edit-Columns' of the GridView.
    - Add a 'template-field'

    - Hit OK.

    - Now, go to the 'Edit-Template' of the GridView.
    - In the 'Column[0]' of the Item-Template, drag-drop a CheckBox
    - Check out whats the ID of the CheckBox (must be CheckBox1)

    -- That's it.
    Now Stop 'Editing Template'

     In the Code-Behind use the following code :

    foreach (GridViewRow gr in GridView1.Rows)
            {
                CheckBox cb = (CheckBox)gr.Cells[0].FindControl("CheckBox1");
                if (cb.Checked)
                {
                      // do ur job here

                }
            }

    thus u can access ur checkbox by iterating thru the GridView Rows.

     

    hope this explained alot for u

    "Sometimes, Difficult things are possible"
Page 1 of 1 (8 items)