PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 1.00 average.

Create checkbox in gridview column at runtime

 
 
Tony WONG
Guest
Posts: n/a
 
      19th Apr 2010
The gridview is created at runtime

there is a column for checkbox (non-databind)

i can create a blank column by the code

Dim tfSelect As New TemplateField
tfSelect.ItemStyle.Width = 80
mygrid.Columns.Add(tfSelect)

but i do not know how to add the checkbox in the column

grateful for any assistance.

thanks.

tony


 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      19th Apr 2010
"Tony WONG" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> The gridview is created at runtime
>
> there is a column for checkbox (non-databind)
>
> i can create a blank column by the code
>
> Dim tfSelect As New TemplateField
> tfSelect.ItemStyle.Width = 80
> mygrid.Columns.Add(tfSelect)
>
> but i do not know how to add the checkbox in the column


Not quite sure if the syntax is correct as I never go anywhere near VB.NET,
but it's probably something like:

Dim MyCB As New CheckBox
' set any properties on MyCB as necessary
mygrid.Columns(0).Controls.Add(MyCB)

Obviously, you'll need to modify the column number in the third line
above...

Alternatively, you may be able to do this with the tfSelect object directly,
e.g.

Dim tfSelect As New TemplateField
tfSelect.ItemStyle.Width = 80
Dim MyCB As New CheckBox
tfSelect.Controls.Add(MyCB)
mygrid.Columns.Add(tfSelect)


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Tony WONG
Guest
Posts: n/a
 
      20th Apr 2010
Thanks a lot.

i can't do it with just a line of code

finally i make it by refering a Class.


"Mark Rae [MVP]" <(E-Mail Removed)>
???????:583FB059-A495-4DA3-B6DA-(E-Mail Removed)...
> "Tony WONG" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>> The gridview is created at runtime
>>
>> there is a column for checkbox (non-databind)
>>
>> i can create a blank column by the code
>>
>> Dim tfSelect As New TemplateField
>> tfSelect.ItemStyle.Width = 80
>> mygrid.Columns.Add(tfSelect)
>>
>> but i do not know how to add the checkbox in the column

>
> Not quite sure if the syntax is correct as I never go anywhere near
> VB.NET, but it's probably something like:
>
> Dim MyCB As New CheckBox
> ' set any properties on MyCB as necessary
> mygrid.Columns(0).Controls.Add(MyCB)
>
> Obviously, you'll need to modify the column number in the third line
> above...
>
> Alternatively, you may be able to do this with the tfSelect object
> directly, e.g.
>
> Dim tfSelect As New TemplateField
> tfSelect.ItemStyle.Width = 80
> Dim MyCB As New CheckBox
> tfSelect.Controls.Add(MyCB)
> mygrid.Columns.Add(tfSelect)
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      20th Apr 2010
"Tony WONG" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

[please don't top-post]


> Thanks a lot.


You're welcome.


> I can't do it with just a line of code


I don't believe I ever suggested that you could...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making customValidator for a checkbox column in a gridview Andy B. Microsoft ASP .NET 1 12th Feb 2009 01:17 PM
Dynamically set the checkbox column in a gridview Robert Smith Microsoft ASP .NET 3 8th Mar 2008 04:46 AM
GridView - Accessing Values on Click of CheckBox Column Adotek Microsoft ASP .NET 1 29th May 2007 09:54 PM
Adding a column to a GridView at Runtime and DataFormatString Eamonn Microsoft ASP .NET 4 17th May 2006 11:38 AM
Setting GridVIew column widths at runtime =?Utf-8?B?U3RldmUgQnVnZGVu?= Microsoft ASP .NET 5 7th Mar 2006 12:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:35 AM.