Solved

ASP.net GridView with extra check box column

Posted on 2011-02-21
5
504 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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.…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

20 Experts available now in Live!

Get 1:1 Help Now