473,396 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

CheckBox control in a datagrid

Hello, I have a datagrid that brings some information from a query. I need
to have a checkbox in each row so the user can select the rows he wants to
reprint. Is it possible to have a checkbox control in a datagrid? Now I
have a Select column but the problem is that the user needs to select more
than one record and send them all to print, instead of being one by one like
is now with the Select column.

Another question, is it possible to have a row with diferent color in a
grid? For example I have a column called Inv. that brings the inventory
stock and everytime they have 0 in this field they want to see the row in
color red so they can identify they're out of ctock for that item, and the
items that have more than 0 still show in color black. Is this possible?

Thanks in advance
jennyfer
Nov 19 '05 #1
10 2394
Jennyfer:
Take a look at: http://openmymind.net/databinding/index.html it should
atleast answer your second question. Basically you can use the
OnItemDataBound even, get the data being bound and if it's something (like a
0) give you the control to change UI elements (like a red background).

As for your first question. You can use a CheckBox control in each row, and
add a 'Print' button at the bottom (in the footer template). When the
button is clicked, you loop through each row of the grid (for each row as
DataGridItem in Grid.Items) find the checkbox:

dim chk as Checkbox = (CheckBox)row.FindControls("checkBoxId")
if not chk is nothing andalso chk.Checked = true then
'this item is checked, maybe add them all to arraylists, then loop
through those and print each corresponding record
end if
the tutorial should help you with that as well :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jennyfer J Barco" <pd*****@nospam.wdsinc.com> wrote in message
news:OI*************@TK2MSFTNGP14.phx.gbl...
Hello, I have a datagrid that brings some information from a query. I need
to have a checkbox in each row so the user can select the rows he wants to
reprint. Is it possible to have a checkbox control in a datagrid? Now I
have a Select column but the problem is that the user needs to select more
than one record and send them all to print, instead of being one by one like is now with the Select column.

Another question, is it possible to have a row with diferent color in a
grid? For example I have a column called Inv. that brings the inventory
stock and everytime they have 0 in this field they want to see the row in
color red so they can identify they're out of ctock for that item, and the
items that have more than 0 still show in color black. Is this possible?

Thanks in advance
jennyfer

Nov 19 '05 #2
Jennyfer:
Take a look at: http://openmymind.net/databinding/index.html it should
atleast answer your second question. Basically you can use the
OnItemDataBound even, get the data being bound and if it's something (like a
0) give you the control to change UI elements (like a red background).

As for your first question. You can use a CheckBox control in each row, and
add a 'Print' button at the bottom (in the footer template). When the
button is clicked, you loop through each row of the grid (for each row as
DataGridItem in Grid.Items) find the checkbox:

dim chk as Checkbox = (CheckBox)row.FindControls("checkBoxId")
if not chk is nothing andalso chk.Checked = true then
'this item is checked, maybe add them all to arraylists, then loop
through those and print each corresponding record
end if
the tutorial should help you with that as well :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jennyfer J Barco" <pd*****@nospam.wdsinc.com> wrote in message
news:OI*************@TK2MSFTNGP14.phx.gbl...
Hello, I have a datagrid that brings some information from a query. I need
to have a checkbox in each row so the user can select the rows he wants to
reprint. Is it possible to have a checkbox control in a datagrid? Now I
have a Select column but the problem is that the user needs to select more
than one record and send them all to print, instead of being one by one like is now with the Select column.

Another question, is it possible to have a row with diferent color in a
grid? For example I have a column called Inv. that brings the inventory
stock and everytime they have 0 in this field they want to see the row in
color red so they can identify they're out of ctock for that item, and the
items that have more than 0 still show in color black. Is this possible?

Thanks in advance
jennyfer

Nov 19 '05 #3
Thanks so much, the first part worked perfectly, but creating a checkbox in
a datagrid is the problem. In the properties of the grid I can't find a way
to define the column as a checkbox type.

Thanks so much

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:up**************@TK2MSFTNGP10.phx.gbl...
Jennyfer:
Take a look at: http://openmymind.net/databinding/index.html it should
atleast answer your second question. Basically you can use the
OnItemDataBound even, get the data being bound and if it's something (like a 0) give you the control to change UI elements (like a red background).

As for your first question. You can use a CheckBox control in each row, and add a 'Print' button at the bottom (in the footer template). When the
button is clicked, you loop through each row of the grid (for each row as
DataGridItem in Grid.Items) find the checkbox:

dim chk as Checkbox = (CheckBox)row.FindControls("checkBoxId")
if not chk is nothing andalso chk.Checked = true then
'this item is checked, maybe add them all to arraylists, then loop
through those and print each corresponding record
end if
the tutorial should help you with that as well :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jennyfer J Barco" <pd*****@nospam.wdsinc.com> wrote in message
news:OI*************@TK2MSFTNGP14.phx.gbl...
Hello, I have a datagrid that brings some information from a query. I need to have a checkbox in each row so the user can select the rows he wants to reprint. Is it possible to have a checkbox control in a datagrid? Now I
have a Select column but the problem is that the user needs to select more than one record and send them all to print, instead of being one by one

like
is now with the Select column.

Another question, is it possible to have a row with diferent color in a
grid? For example I have a column called Inv. that brings the inventory
stock and everytime they have 0 in this field they want to see the row in color red so they can identify they're out of ctock for that item, and the items that have more than 0 still show in color black. Is this possible?

Thanks in advance
jennyfer


Nov 19 '05 #4
Thanks so much, the first part worked perfectly, but creating a checkbox in
a datagrid is the problem. In the properties of the grid I can't find a way
to define the column as a checkbox type.

Thanks so much

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:up**************@TK2MSFTNGP10.phx.gbl...
Jennyfer:
Take a look at: http://openmymind.net/databinding/index.html it should
atleast answer your second question. Basically you can use the
OnItemDataBound even, get the data being bound and if it's something (like a 0) give you the control to change UI elements (like a red background).

As for your first question. You can use a CheckBox control in each row, and add a 'Print' button at the bottom (in the footer template). When the
button is clicked, you loop through each row of the grid (for each row as
DataGridItem in Grid.Items) find the checkbox:

dim chk as Checkbox = (CheckBox)row.FindControls("checkBoxId")
if not chk is nothing andalso chk.Checked = true then
'this item is checked, maybe add them all to arraylists, then loop
through those and print each corresponding record
end if
the tutorial should help you with that as well :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jennyfer J Barco" <pd*****@nospam.wdsinc.com> wrote in message
news:OI*************@TK2MSFTNGP14.phx.gbl...
Hello, I have a datagrid that brings some information from a query. I need to have a checkbox in each row so the user can select the rows he wants to reprint. Is it possible to have a checkbox control in a datagrid? Now I
have a Select column but the problem is that the user needs to select more than one record and send them all to print, instead of being one by one

like
is now with the Select column.

Another question, is it possible to have a row with diferent color in a
grid? For example I have a column called Inv. that brings the inventory
stock and everytime they have 0 in this field they want to see the row in color red so they can identify they're out of ctock for that item, and the items that have more than 0 still show in color black. Is this possible?

Thanks in advance
jennyfer


Nov 19 '05 #5
You can create a TemplateColumn and add any type of control you need,
it would look something like:

<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox runat="server" ... />
</ItemTemplate>
</asp:TemplateColumn>

I have an article with some tips on using controls from inside a grid
template column (it uses a DropDownList, but the workings are all the
same):

http://odetocode.com/Articles/231.aspx

HTH!

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 14 Feb 2005 16:37:19 -0500, "Jennyfer J Barco"
<pd*****@nospam.wdsinc.com> wrote:
Thanks so much, the first part worked perfectly, but creating a checkbox in
a datagrid is the problem. In the properties of the grid I can't find a way
to define the column as a checkbox type.

Thanks so much

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:up**************@TK2MSFTNGP10.phx.gbl...
Jennyfer:
Take a look at: http://openmymind.net/databinding/index.html it should
atleast answer your second question. Basically you can use the
OnItemDataBound even, get the data being bound and if it's something (like

a
0) give you the control to change UI elements (like a red background).

As for your first question. You can use a CheckBox control in each row,

and
add a 'Print' button at the bottom (in the footer template). When the
button is clicked, you loop through each row of the grid (for each row as
DataGridItem in Grid.Items) find the checkbox:

dim chk as Checkbox = (CheckBox)row.FindControls("checkBoxId")
if not chk is nothing andalso chk.Checked = true then
'this item is checked, maybe add them all to arraylists, then loop
through those and print each corresponding record
end if
the tutorial should help you with that as well :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jennyfer J Barco" <pd*****@nospam.wdsinc.com> wrote in message
news:OI*************@TK2MSFTNGP14.phx.gbl...
> Hello, I have a datagrid that brings some information from a query. Ineed > to have a checkbox in each row so the user can select the rows he wantsto > reprint. Is it possible to have a checkbox control in a datagrid? Now I
> have a Select column but the problem is that the user needs to selectmore > than one record and send them all to print, instead of being one by one

like
> is now with the Select column.
>
> Another question, is it possible to have a row with diferent color in a
> grid? For example I have a column called Inv. that brings the inventory
> stock and everytime they have 0 in this field they want to see the rowin > color red so they can identify they're out of ctock for that item, andthe > items that have more than 0 still show in color black. Is this possible?
>
> Thanks in advance
> jennyfer
>
>



Nov 19 '05 #6
You can create a TemplateColumn and add any type of control you need,
it would look something like:

<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox runat="server" ... />
</ItemTemplate>
</asp:TemplateColumn>

I have an article with some tips on using controls from inside a grid
template column (it uses a DropDownList, but the workings are all the
same):

http://odetocode.com/Articles/231.aspx

HTH!

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 14 Feb 2005 16:37:19 -0500, "Jennyfer J Barco"
<pd*****@nospam.wdsinc.com> wrote:
Thanks so much, the first part worked perfectly, but creating a checkbox in
a datagrid is the problem. In the properties of the grid I can't find a way
to define the column as a checkbox type.

Thanks so much

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:up**************@TK2MSFTNGP10.phx.gbl...
Jennyfer:
Take a look at: http://openmymind.net/databinding/index.html it should
atleast answer your second question. Basically you can use the
OnItemDataBound even, get the data being bound and if it's something (like

a
0) give you the control to change UI elements (like a red background).

As for your first question. You can use a CheckBox control in each row,

and
add a 'Print' button at the bottom (in the footer template). When the
button is clicked, you loop through each row of the grid (for each row as
DataGridItem in Grid.Items) find the checkbox:

dim chk as Checkbox = (CheckBox)row.FindControls("checkBoxId")
if not chk is nothing andalso chk.Checked = true then
'this item is checked, maybe add them all to arraylists, then loop
through those and print each corresponding record
end if
the tutorial should help you with that as well :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jennyfer J Barco" <pd*****@nospam.wdsinc.com> wrote in message
news:OI*************@TK2MSFTNGP14.phx.gbl...
> Hello, I have a datagrid that brings some information from a query. Ineed > to have a checkbox in each row so the user can select the rows he wantsto > reprint. Is it possible to have a checkbox control in a datagrid? Now I
> have a Select column but the problem is that the user needs to selectmore > than one record and send them all to print, instead of being one by one

like
> is now with the Select column.
>
> Another question, is it possible to have a row with diferent color in a
> grid? For example I have a column called Inv. that brings the inventory
> stock and everytime they have 0 in this field they want to see the rowin > color red so they can identify they're out of ctock for that item, andthe > items that have more than 0 still show in color black. Is this possible?
>
> Thanks in advance
> jennyfer
>
>



Nov 19 '05 #7
In C#

http://www.geocities.com/jeff_louie/net_checkbox.htm

Regards,
Jeff
Is it possible to have a checkbox control in a datagrid?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #8
In C#

http://www.geocities.com/jeff_louie/net_checkbox.htm

Regards,
Jeff
Is it possible to have a checkbox control in a datagrid?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 19 '05 #9
Thanks it worked.

Now I have a question, if a need to bind a checkbox control to a field that
has a value "Y" or "N", if the data is "Y" I need to appear checked, if "N"
I need it to appear unchecked. How can I do this? where do I bind the
control?

Now in the grid I have
<asp:BoundColumn DataField="lcalculatedlastfreeday"
SortExpression="lcalculatedlastfreeday" HeaderText="Calc last free
day"></asp:BoundColumn> and it's appearing the "N" or "Y". I need to appear
a checkbox instead of the "Y", "N" value.

Thanks in advance
jennyfer
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:us********************************@4ax.com...
You can create a TemplateColumn and add any type of control you need,
it would look something like:

<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox runat="server" ... />
</ItemTemplate>
</asp:TemplateColumn>

I have an article with some tips on using controls from inside a grid
template column (it uses a DropDownList, but the workings are all the
same):

http://odetocode.com/Articles/231.aspx

HTH!

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 14 Feb 2005 16:37:19 -0500, "Jennyfer J Barco"
<pd*****@nospam.wdsinc.com> wrote:
Thanks so much, the first part worked perfectly, but creating a checkbox ina datagrid is the problem. In the properties of the grid I can't find a wayto define the column as a checkbox type.

Thanks so much

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:up**************@TK2MSFTNGP10.phx.gbl...
Jennyfer:
Take a look at: http://openmymind.net/databinding/index.html it should
atleast answer your second question. Basically you can use the
OnItemDataBound even, get the data being bound and if it's something (like
a
0) give you the control to change UI elements (like a red background).

As for your first question. You can use a CheckBox control in each
row,and
add a 'Print' button at the bottom (in the footer template). When the
button is clicked, you loop through each row of the grid (for each row
as DataGridItem in Grid.Items) find the checkbox:

dim chk as Checkbox = (CheckBox)row.FindControls("checkBoxId")
if not chk is nothing andalso chk.Checked = true then
'this item is checked, maybe add them all to arraylists, then loop
through those and print each corresponding record
end if
the tutorial should help you with that as well :)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Jennyfer J Barco" <pd*****@nospam.wdsinc.com> wrote in message
news:OI*************@TK2MSFTNGP14.phx.gbl...
> Hello, I have a datagrid that brings some information from a query. I

need
> to have a checkbox in each row so the user can select the rows he wantsto
> reprint. Is it possible to have a checkbox control in a datagrid? Now
I > have a Select column but the problem is that the user needs to select

more
> than one record and send them all to print, instead of being one by one like
> is now with the Select column.
>
> Another question, is it possible to have a row with diferent color in a > grid? For example I have a column called Inv. that brings the inventory > stock and everytime they have 0 in this field they want to see the rowin
> color red so they can identify they're out of ctock for that item,
andthe
> items that have more than 0 still show in color black. Is this

possible? >
> Thanks in advance
> jennyfer
>
>

Nov 19 '05 #10
Hi Jennyfer:

There is an example in the following support article that show how to
catch the data binding event to set the checked state of the checkbox.

You'll need to use a TemplateColumn instead of a BoundColumn - the
article shows how you can do this.

http://support.microsoft.com/kb/306227/EN-US/

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 17 Feb 2005 11:28:55 -0500, "Jennyfer J Barco"
<pd*****@nospam.wdsinc.com> wrote:
Thanks it worked.

Now I have a question, if a need to bind a checkbox control to a field that
has a value "Y" or "N", if the data is "Y" I need to appear checked, if "N"
I need it to appear unchecked. How can I do this? where do I bind the
control?

Now in the grid I have
<asp:BoundColumn DataField="lcalculatedlastfreeday"
SortExpression="lcalculatedlastfreeday" HeaderText="Calc last free
day"></asp:BoundColumn> and it's appearing the "N" or "Y". I need to appear
a checkbox instead of the "Y", "N" value.

Thanks in advance
jennyfer
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:us********************************@4ax.com.. .
You can create a TemplateColumn and add any type of control you need,
it would look something like:

<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox runat="server" ... />
</ItemTemplate>
</asp:TemplateColumn>

I have an article with some tips on using controls from inside a grid
template column (it uses a DropDownList, but the workings are all the
same):

http://odetocode.com/Articles/231.aspx

HTH!

--
Scott
http://www.OdeToCode.com/blogs/scott/
On Mon, 14 Feb 2005 16:37:19 -0500, "Jennyfer J Barco"
<pd*****@nospam.wdsinc.com> wrote:
>Thanks so much, the first part worked perfectly, but creating a checkboxin >a datagrid is the problem. In the properties of the grid I can't find away >to define the column as a checkbox type.
>
>Thanks so much
>
>"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
>wrote in message news:up**************@TK2MSFTNGP10.phx.gbl...
>> Jennyfer:
>> Take a look at: http://openmymind.net/databinding/index.html it should
>> atleast answer your second question. Basically you can use the
>> OnItemDataBound even, get the data being bound and if it's something(like >a
>> 0) give you the control to change UI elements (like a red background).
>>
>> As for your first question. You can use a CheckBox control in eachrow, >and
>> add a 'Print' button at the bottom (in the footer template). When the
>> button is clicked, you loop through each row of the grid (for each rowas >> DataGridItem in Grid.Items) find the checkbox:
>>
>> dim chk as Checkbox = (CheckBox)row.FindControls("checkBoxId")
>> if not chk is nothing andalso chk.Checked = true then
>> 'this item is checked, maybe add them all to arraylists, then loop
>> through those and print each corresponding record
>> end if
>>
>>
>> the tutorial should help you with that as well :)
>>
>> Karl
>>
>> --
>> MY ASP.Net tutorials
>> http://www.openmymind.net/
>>
>>
>> "Jennyfer J Barco" <pd*****@nospam.wdsinc.com> wrote in message
>> news:OI*************@TK2MSFTNGP14.phx.gbl...
>> > Hello, I have a datagrid that brings some information from a query. I
>need
>> > to have a checkbox in each row so the user can select the rows hewants >to
>> > reprint. Is it possible to have a checkbox control in a datagrid? NowI >> > have a Select column but the problem is that the user needs to select
>more
>> > than one record and send them all to print, instead of being one byone >> like
>> > is now with the Select column.
>> >
>> > Another question, is it possible to have a row with diferent color ina >> > grid? For example I have a column called Inv. that brings theinventory >> > stock and everytime they have 0 in this field they want to see therow >in
>> > color red so they can identify they're out of ctock for that item,and >the
>> > items that have more than 0 still show in color black. Is thispossible? >> >
>> > Thanks in advance
>> > jennyfer
>> >
>> >
>>
>>
>


Nov 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: michael walser | last post by:
display checkbox in datagrid. I find that there are 3 status: checked - check box with click icon unchecked - blank in check box unknown - click icon but color in gray..... How can I set the...
1
by: Simon | last post by:
Hi Guys, I'm trying to use a checkbox control in a datagrid. The objective is to display readonly Customers from a database, then allow a user to select customers with the checkbox. Then,...
1
by: Machi | last post by:
Let say i select rows of records with 4 columns from Database and want to display the data in DataGrid (ASP.NEt Server Control) with one column which must be displayed in CheckBox layout. For the...
0
by: Jennyfer J Barco | last post by:
Hello, I have a datagrid that brings some information from a query. I need to have a checkbox in each row so the user can select the rows he wants to reprint. Is it possible to have a checkbox...
2
by: sushil bogam via .NET 247 | last post by:
(Type your message here) hi there please help me with datagrid control i want to add a checkbox in datagrid and also want to trap the check bok check or click event and also want to maintain the...
1
by: MilanB | last post by:
I wish to access CheckBox control in ItemTemplate, to set or get value. I use next code on event: ItemDataBound(...) //------------- e.Item.Cells.FindControl("CheckBox1") //------------- to...
4
by: Steven | last post by:
I am writing VB.NET, Can I add the checkbox control to a particular column on the datagrid? Thanks!
1
by: ursridhu | last post by:
hi guys, i am new to vc++, How to add a checkbox column to a datagrid. is it possible to add a checkbox in datagrid?? if yes please send me how we can do it. Thanx in advance its ur'sridhu
1
by: Adewunmi Agbato | last post by:
I just developing my web design skills. I have a Datagrid with 2 textbox template columnsand two checkbox template columns. I have two other Textbox controls and two CheckBox controls. I have an...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.