By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,712 Members | 1,430 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,712 IT Pros & Developers. It's quick & easy.

CheckBox control in a datagrid

P: n/a
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
Share this Question
Share on Google+
10 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.