Solved

ASP.net GridView with extra check box column

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

831 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