简体   繁体   中英

Using a CheckBox to Select Rows in an ASP.NET GridView

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.

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

如果您使用的是ASP.NET,我认为链接可以帮助您

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM