Solved

ASP.net GridView with extra check box column

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

860 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