473,471 Members | 4,629 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

convert boolean to checkbox in Item_Bound event

ICollection CreateDataSource() {
dt.Columns.Add(new DataColumn("ReportInclude", typeof(Boolean)));
for (int i=0; i<=10; i++) { dr = dt.NewRow(); dr[0] = 0;
dt.Rows.Add(dr); }

void Page_Load(Object sender, EventArgs e)
{ ItemsGrid.DataSource = CreateDataSource();

void Item_Bound(Object sender, DataGridItemEventArgs e)
{
// Use the ItemDataBound event to customize the DataGrid control.
// The ItemDataBound event allows you to access the data before
// the item is displayed in the control.

????? How do I convert the boolean value to a checkbox. I don't want
to see true/false, I want to see a checkbox, checked or not.

Thank you,
-Greg
May 2 '06 #1
6 2947
something like:

you might have to check for e.Item.ItemType to make sure it isn't a
header/footer...
CheckBox check = (CheckBox)
e.Item.FindControl("IdOfTheRunatServerCheckbox");
check.Checked =
Convert.ToBoolean(((DataRowView)e.Item.DataItem)["ReportInclude"]);

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"hazz" <hazz@sonic_net> wrote in message
news:eF**************@TK2MSFTNGP04.phx.gbl...
ICollection CreateDataSource() {
dt.Columns.Add(new DataColumn("ReportInclude", typeof(Boolean)));
for (int i=0; i<=10; i++) { dr = dt.NewRow(); dr[0] = 0;
dt.Rows.Add(dr); }

void Page_Load(Object sender, EventArgs e)
{ ItemsGrid.DataSource = CreateDataSource();

void Item_Bound(Object sender, DataGridItemEventArgs e)
{
// Use the ItemDataBound event to customize the DataGrid control.
// The ItemDataBound event allows you to access the data before
// the item is displayed in the control.

????? How do I convert the boolean value to a checkbox. I don't want
to see true/false, I want to see a checkbox, checked or not.

Thank you,
-Greg

May 2 '06 #2
Thank you so much Karl.

One follow up question having to do with the design time structure of the
checkbox column for the.FindControl("IdOfTheRunatServerCheckbox"); Where
does IdOfTheRunatServerCheckbox go within the <asp:> </asp?> as listed here
from my aspx page?

<asp:DataGrid id="ItemsGrid" runat="server"
OnItemDataBound="Item_Bound">
<HeaderStyle BackColor="#00aaaa"> </HeaderStyle>
<FooterStyle BackColor="#00aaaa"></FooterStyle>
</asp:DataGrid>

Thank you,
Greg

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:u0**************@TK2MSFTNGP04.phx.gbl...
something like:

you might have to check for e.Item.ItemType to make sure it isn't a
header/footer...
CheckBox check = (CheckBox)
e.Item.FindControl("IdOfTheRunatServerCheckbox");
check.Checked =
Convert.ToBoolean(((DataRowView)e.Item.DataItem)["ReportInclude"]);

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"hazz" <hazz@sonic_net> wrote in message
news:eF**************@TK2MSFTNGP04.phx.gbl...
ICollection CreateDataSource() {
dt.Columns.Add(new DataColumn("ReportInclude", typeof(Boolean)));
for (int i=0; i<=10; i++) { dr = dt.NewRow(); dr[0] = 0;
dt.Rows.Add(dr); }

void Page_Load(Object sender, EventArgs e)
{ ItemsGrid.DataSource = CreateDataSource();

void Item_Bound(Object sender, DataGridItemEventArgs e)
{
// Use the ItemDataBound event to customize the DataGrid control.
// The ItemDataBound event allows you to access the data before
// the item is displayed in the control.

????? How do I convert the boolean value to a checkbox. I don't want
to see true/false, I want to see a checkbox, checked or not.

Thank you,
-Greg


May 2 '06 #3
Sorry, I zoned out the entire datagrid thing :)

You'll need to turn off autogeneratecolumns and output it yourself:

<asp:DataGrid ID="grid" runat="Server" OnItemDataBound="Item_Bound">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="myCheckbox" runat="Server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"hazz" <hazz@sonic_net> wrote in message
news:ev**************@TK2MSFTNGP03.phx.gbl...
Thank you so much Karl.

One follow up question having to do with the design time structure of the
checkbox column for the.FindControl("IdOfTheRunatServerCheckbox"); Where
does IdOfTheRunatServerCheckbox go within the <asp:> </asp?> as listed
here from my aspx page?

<asp:DataGrid id="ItemsGrid" runat="server"
OnItemDataBound="Item_Bound">
<HeaderStyle BackColor="#00aaaa"> </HeaderStyle>
<FooterStyle BackColor="#00aaaa"></FooterStyle>
</asp:DataGrid>

Thank you,
Greg

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:u0**************@TK2MSFTNGP04.phx.gbl...
something like:

you might have to check for e.Item.ItemType to make sure it isn't a
header/footer...
CheckBox check = (CheckBox)
e.Item.FindControl("IdOfTheRunatServerCheckbox");
check.Checked =
Convert.ToBoolean(((DataRowView)e.Item.DataItem)["ReportInclude"]);

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"hazz" <hazz@sonic_net> wrote in message
news:eF**************@TK2MSFTNGP04.phx.gbl...
ICollection CreateDataSource() {
dt.Columns.Add(new DataColumn("ReportInclude", typeof(Boolean)));
for (int i=0; i<=10; i++) { dr = dt.NewRow(); dr[0] = 0;
dt.Rows.Add(dr); }

void Page_Load(Object sender, EventArgs e)
{ ItemsGrid.DataSource = CreateDataSource();

void Item_Bound(Object sender, DataGridItemEventArgs e)
{
// Use the ItemDataBound event to customize the DataGrid control.
// The ItemDataBound event allows you to access the data before
// the item is displayed in the control.

????? How do I convert the boolean value to a checkbox. I don't
want to see true/false, I want to see a checkbox, checked or not.

Thank you,
-Greg



May 2 '06 #4
When I add the following to the gridview
<Columns>
<asp:TemplateColumn>
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1"
Text="Taxable"
runat="server"/>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>

CheckBox check = (CheckBox)e.Item.FindControl("CheckBox1") returns a null.
"hazz" <hazz@sonic_net> wrote in message
news:ev**************@TK2MSFTNGP03.phx.gbl...
Thank you so much Karl.

One follow up question having to do with the design time structure of the
checkbox column for the.FindControl("IdOfTheRunatServerCheckbox"); Where
does IdOfTheRunatServerCheckbox go within the <asp:> </asp?> as listed
here from my aspx page?

<asp:DataGrid id="ItemsGrid" runat="server"
OnItemDataBound="Item_Bound">
<HeaderStyle BackColor="#00aaaa"> </HeaderStyle>
<FooterStyle BackColor="#00aaaa"></FooterStyle>
</asp:DataGrid>

Thank you,
Greg

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:u0**************@TK2MSFTNGP04.phx.gbl...
something like:

you might have to check for e.Item.ItemType to make sure it isn't a
header/footer...
CheckBox check = (CheckBox)
e.Item.FindControl("IdOfTheRunatServerCheckbox");
check.Checked =
Convert.ToBoolean(((DataRowView)e.Item.DataItem)["ReportInclude"]);

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"hazz" <hazz@sonic_net> wrote in message
news:eF**************@TK2MSFTNGP04.phx.gbl...
ICollection CreateDataSource() {
dt.Columns.Add(new DataColumn("ReportInclude", typeof(Boolean)));
for (int i=0; i<=10; i++) { dr = dt.NewRow(); dr[0] = 0;
dt.Rows.Add(dr); }

void Page_Load(Object sender, EventArgs e)
{ ItemsGrid.DataSource = CreateDataSource();

void Item_Bound(Object sender, DataGridItemEventArgs e)
{
// Use the ItemDataBound event to customize the DataGrid control.
// The ItemDataBound event allows you to access the data before
// the item is displayed in the control.

????? How do I convert the boolean value to a checkbox. I don't
want to see true/false, I want to see a checkbox, checked or not.

Thank you,
-Greg



May 2 '06 #5
Thanks Karl, I'm getting closer !! I have checkable checkboxes. -Greg

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:OT**************@TK2MSFTNGP03.phx.gbl...
Sorry, I zoned out the entire datagrid thing :)

You'll need to turn off autogeneratecolumns and output it yourself:

<asp:DataGrid ID="grid" runat="Server" OnItemDataBound="Item_Bound">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="myCheckbox" runat="Server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"hazz" <hazz@sonic_net> wrote in message
news:ev**************@TK2MSFTNGP03.phx.gbl...
Thank you so much Karl.

One follow up question having to do with the design time structure of the
checkbox column for the.FindControl("IdOfTheRunatServerCheckbox"); Where
does IdOfTheRunatServerCheckbox go within the <asp:> </asp?> as listed
here from my aspx page?

<asp:DataGrid id="ItemsGrid" runat="server"
OnItemDataBound="Item_Bound">
<HeaderStyle BackColor="#00aaaa"> </HeaderStyle>
<FooterStyle BackColor="#00aaaa"></FooterStyle>
</asp:DataGrid>

Thank you,
Greg

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:u0**************@TK2MSFTNGP04.phx.gbl...
something like:

you might have to check for e.Item.ItemType to make sure it isn't a
header/footer...
CheckBox check = (CheckBox)
e.Item.FindControl("IdOfTheRunatServerCheckbox");
check.Checked =
Convert.ToBoolean(((DataRowView)e.Item.DataItem)["ReportInclude"]);

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"hazz" <hazz@sonic_net> wrote in message
news:eF**************@TK2MSFTNGP04.phx.gbl...
ICollection CreateDataSource() {
dt.Columns.Add(new DataColumn("ReportInclude", typeof(Boolean)));
for (int i=0; i<=10; i++) { dr = dt.NewRow(); dr[0] = 0;
dt.Rows.Add(dr); }

void Page_Load(Object sender, EventArgs e)
{ ItemsGrid.DataSource = CreateDataSource();

void Item_Bound(Object sender, DataGridItemEventArgs e)
{
// Use the ItemDataBound event to customize the DataGrid control.
// The ItemDataBound event allows you to access the data before
// the item is displayed in the control.

????? How do I convert the boolean value to a checkbox. I don't
want to see true/false, I want to see a checkbox, checked or not.

Thank you,
-Greg



May 2 '06 #6
I kinda hinted at that first...but it wasn't clear, sorry..
If (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
///do stuff
}

there won't be a "CheckBox1" when ItemType is Header or Footer or etc...
Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"hazz" <hazz@sonic_net> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
When I add the following to the gridview
<Columns>
<asp:TemplateColumn>
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1"
Text="Taxable"
runat="server"/>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>

CheckBox check = (CheckBox)e.Item.FindControl("CheckBox1") returns a
null.
"hazz" <hazz@sonic_net> wrote in message
news:ev**************@TK2MSFTNGP03.phx.gbl...
Thank you so much Karl.

One follow up question having to do with the design time structure of the
checkbox column for the.FindControl("IdOfTheRunatServerCheckbox"); Where
does IdOfTheRunatServerCheckbox go within the <asp:> </asp?> as listed
here from my aspx page?

<asp:DataGrid id="ItemsGrid" runat="server"
OnItemDataBound="Item_Bound">
<HeaderStyle BackColor="#00aaaa"> </HeaderStyle>
<FooterStyle BackColor="#00aaaa"></FooterStyle>
</asp:DataGrid>

Thank you,
Greg

"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:u0**************@TK2MSFTNGP04.phx.gbl...
something like:

you might have to check for e.Item.ItemType to make sure it isn't a
header/footer...
CheckBox check = (CheckBox)
e.Item.FindControl("IdOfTheRunatServerCheckbox");
check.Checked =
Convert.ToBoolean(((DataRowView)e.Item.DataItem)["ReportInclude"]);

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"hazz" <hazz@sonic_net> wrote in message
news:eF**************@TK2MSFTNGP04.phx.gbl...
ICollection CreateDataSource() {
dt.Columns.Add(new DataColumn("ReportInclude", typeof(Boolean)));
for (int i=0; i<=10; i++) { dr = dt.NewRow(); dr[0] = 0;
dt.Rows.Add(dr); }

void Page_Load(Object sender, EventArgs e)
{ ItemsGrid.DataSource = CreateDataSource();

void Item_Bound(Object sender, DataGridItemEventArgs e)
{
// Use the ItemDataBound event to customize the DataGrid control.
// The ItemDataBound event allows you to access the data before
// the item is displayed in the control.

????? How do I convert the boolean value to a checkbox. I don't
want to see true/false, I want to see a checkbox, checked or not.

Thank you,
-Greg



May 2 '06 #7

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

Similar topics

3
by: ET | last post by:
I don't know whats the problem, but after I added functions to first verify, then relink linked tables if not found, now I can't convert that database to MDE format. I can split the database, but...
2
by: Raj | last post by:
Hi, When we are sorting the DataGrid Boolean column the grid is becoming redcross. I have my own PPMIPDataGridBoolColumn class inherited from System.Windows.Forms.DataGridBoolColumn. In this...
4
by: Patrick.O.Ige | last post by:
I'm DataBinding a CheckBoxList and i want to get the checkboxes selected when the page is loaded depending on a Boolean value from the Database.. chkDebtor.DataSource = objDR...
6
by: Tim Cartwright | last post by:
I have a page that has the login control on it, nothing else. This page inherits from a master page, neither page has any code in it. This page works perfectly when running on the WebDev debug web...
0
by: dfetrow410 | last post by:
<asp:Content ID="content2" ContentPlaceHolderID="leadercontent" runat="Server"> <asp:DataList ID="DataList2" runat="server" OnItemDataBound = "Item_Bound" CellPadding="1" CellSpacing="1"...
10
by: dba123 | last post by:
Why am I getting this error for Budget? Error: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code Additional information: String was not...
5
by: Learner | last post by:
Hello, Here is the code snippet I got strucked at. I am unable to convert the below line of code to its equavalent vb.net code. could some one please help me with this? static public...
2
by: Carlos Aguayo | last post by:
Hi, Is there a better way to do this? The problem that I have is that x can be "true" or "false" (as type string), or true or false (as boolean type). I'm doing comparisons like... if (eval(x)...
2
by: joecosmides | last post by:
I have a microsoft access front end and backend database for multi- user use. I have the back end located on a server that also is an IIS webserver. I've created a few ASP pages that pull customer...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.