views:

2271

answers:

4

With a GridView control in .NET is there any way to change the Select option in a GridView to a Checkbox, how do you select multiple rows?

I tried adding a CheckBoxField into my GridView but when I ran it it didn't show up.

+1  A: 

if you are using ASP.NET I think this link will help you

Baget
+1  A: 

Adding checkbox to Gridview is as simple as adding TemplateField of any control.

I tried adding a CheckBoxField into my gridview but when I ran it it didn't show up.

There should be other columns binding data to the grid. Also, check visible property of checkbox.

Refer to this link for more on this. link text

BinaryHacker
I think the problem is that the check box is not bound to any data column, I simply want someone to be able to select multiple items in the list but until they actually press 'go' I don't need any postback events etc. I did originally chekc the visibiltiy property but the default is visible but came to the conclusion above.
flavour404
I tried to add a template field, and a check box but it is still not showing up in each row. I have followed the tutorial, but of course they didn't show the markup so I cannot see what I am doing wrong!
flavour404
Ok, that really worked. Thanks.
flavour404
A: 

I always just add a column to the DataTable that I am binding to.

dt.Columns.Add(new DataColumn("Include", typeof(Boolean)));

Or in my SQL I will have:

declare @include bit
set @include = 0
select 
@include Include,
....

More can be found on my blog here

JBrooks
I like this idea and will check out your blog.
flavour404
A: 

I did work it out in the end, thanks to ExpertSoul for the headsup on the tutorial. This was all I needed in the markup and it worked great:

<asp:TemplateField>
    <ItemTemplate>
        <asp:CheckBox ID="PublicationSelector" runat="server" />
    </ItemTemplate>
</asp:TemplateField>

The other thing that the tutorial had which was great was an onclick event so that you could pick up the id # when the submit button was clicked, which was the next bit...

Great stuff.

flavour404