3

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.

3
  • Which GridView? WinForms, WPF? Other? Commented Jul 14, 2009 at 19:51
  • I think flavour404 is referred to ASP.NET Web Forms. Commented Jul 14, 2009 at 19:56
  • Indeed I do mean a ASP .Net web form. Commented Jul 14, 2009 at 21:33

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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!
1

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

1 Comment

I like this idea and will check out your blog.
1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.