Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.net GridView with extra check box column

Posted on 2011-02-21
5
Medium Priority
?
512 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 7

Accepted Solution

by:
kovilpattiBalu earned 1000 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:Murray Brown
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 1000 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:Murray Brown
ID: 34991636
Thanks . Please see related question
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

715 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