Solved

ASP.net GridView with extra check box column

Posted on 2011-02-21
5
505 Views
Last Modified: 2012-05-11
Hi

In ASP.net 4 I want to query a table so that the results are shown in a GridView that has an extra checkbox column so that the user can choose the items relevant to them. How do i achieve this?

Thanks
0
Comment
Question by:murbro
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
kovilpattiBalu earned 250 total points
ID: 34942257
<asp:datagrid id="dgridSample" runat="server" Width="100%" AutoGenerateColumns="False" Font-Size="8"
CellPadding="3" BorderColor="navy" BorderWidth="1px">
      <ItemStyle CssClass="LabelCaption" BackColor="White"></ItemStyle>
      <HeaderStyle Font-Bold="True" CssClass="LabelCaption" BackColor="LightGray"    HorizontalAlign="Center"></HeaderStyle>
      <Columns>
       other columns..
      <asp:TemplateColumn ItemStyle-HorizontalAlign="Center">
            <HeaderTemplate>
             <asp:checkbox id="chtTop" runat="server"></asp:checkbox>
                  </HeaderTemplate>
            <ItemTemplate>
            <EditItemTemplate>
            <asp:checkbox id="chkOthers" runat="server"></asp:checkbox>
            </EditItemTemplate>
            </ItemTemplate>
            </asp:TemplateColumn>
      </Columns>
</asp:datagrid>
0
 

Author Comment

by:murbro
ID: 34949124
Hi. Thanks. Not sure where to put this code
0
 
LVL 7

Expert Comment

by:kovilpattiBalu
ID: 34949308
hi,

1. put inside your datagrid, that why i gave with datagrid tag..
<asp:datagrid>

</asp:Datagrid>

2. if you want that column at the end, paste the code before below tag
..
    </Columns>
</asp:datagrid>

0
 
LVL 7

Assisted Solution

by:mr_nadger
mr_nadger earned 250 total points
ID: 34950768
Alternative way to do this is through the GUI;
Click on the gridview tasks extender, select Edit Columns
Select Template Field at the bottom of the Available Fields list and hit the Add button
Name the column and set any properties you want, click OK
Click on the tasks extender again, Edit Templates, and you should see the column you just added, drag a checkbox into the template area, click the extender, and End Template Editing, and you're done.

If you're using VB in the code behind, you'll need to findcontrol the checkbox in the selected row
e.g.
If CType(gvwRecipients.SelectedRow.FindControl("chkIsMember"), CheckBox).Checked = True Then...
(or if iterating through all rows in the grid
If CType(gvwRecipients.Rows(idx).FindControl("chkIsMember"), CheckBox).Checked = True
)

A colleague has done this in C# and said you don't need the findcontrol
0
 

Author Closing Comment

by:murbro
ID: 34991636
Thanks . Please see related question
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

947 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

21 Experts available now in Live!

Get 1:1 Help Now