473,395 Members | 2,443 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,395 software developers and data experts.

DataGrid TemplateColumns-- how-to use with CheckBoxes?

Hi everyone,

I'd like to use ItemTemplates in my DataGrid to display one checkbox per
row. The idea being, if field XYZ of a given DataItem is 1 (it's a binary
field) then mark the checkbox. Otherwise, don't.

Does this look like a good approach to the problem, or are there better ways
that someone can share?
.....
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox runat="server" id="chkAddable"
Checked=<%#DataBinder.Eval(Container.DataItem, "XYZ")/>
</ItemTemplate>
</asp:TemplateColumn>
.....

I'd like to cast that DataBinder.Eval() to a boolean, but I'm not sure how
to do it. I've tried a few (bool) casts but I get syntax errors each time.
Thanks for your advice and help.

-Jim

Nov 19 '05 #1
3 1191
SA
Jim:

Maybe this is a copy/paste error, but you have a syntax problem in the
snippet below: you don't have an ending %> for your Checked argument.

I have always intercepted the ItemDataBound event for such things, but that
was really more needed because the user could change the state of the
checkbox (i.e. there was an edit item template too), not sure if that will
be the case for you.

Seems like it should work to me. Do cast to bool, because that will probably
ouput the word "true", which is what you want of course.

HTH,

---

Sven.

"Jim Bancroft" <as******@nowhere.com> wrote in message
news:OE**************@TK2MSFTNGP15.phx.gbl...
Hi everyone,

I'd like to use ItemTemplates in my DataGrid to display one checkbox per row. The idea being, if field XYZ of a given DataItem is 1 (it's a binary
field) then mark the checkbox. Otherwise, don't.

Does this look like a good approach to the problem, or are there better ways that someone can share?
....
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox runat="server" id="chkAddable"
Checked=<%#DataBinder.Eval(Container.DataItem, "XYZ")/>
</ItemTemplate>
</asp:TemplateColumn>
....

I'd like to cast that DataBinder.Eval() to a boolean, but I'm not sure how
to do it. I've tried a few (bool) casts but I get syntax errors each time. Thanks for your advice and help.

-Jim


Nov 19 '05 #2
Thanks, Sven. I did make a copy/paste error. As to your suggestion, I'll
keep plugging away.

-Jim.
Nov 19 '05 #3
SA
You could always add a protected method to your codebehind file like this

Protected Function BitToBooleanString (ByVal bitValue As Integer) As String

If (bitValue = 0) Then
Return "False"
Else
Return "True"
End If

End Function

You can then call the function from your aspx file

<%# BitToBooleanString(DataBinder.Eval(Container.DataI tem, "XYZ")) %>

HTH

---

Sven.

"Jim Bancroft" <as******@nowhere.com> wrote in message
news:#g**************@tk2msftngp13.phx.gbl...
Thanks, Sven. I did make a copy/paste error. As to your suggestion, I'll
keep plugging away.

-Jim.

Nov 19 '05 #4

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

Similar topics

2
by: anonymous | last post by:
I have created a DataGrid control with checkboxes, TextBoxes, ComboBoxes, and NumericUpDowns. Since I used the DataGridBoolColumn, the checkbox is displayed in the center of the cell, horizontally...
0
by: momo | last post by:
Hello all, I need help with this. I have a datagrid (dg1) with checkboxes and I want when some rows are selected to populate another datagrid (dg2) with the selected rows from (dg1). Thanks ...
2
by: john | last post by:
I posted this question to comp.lang.javascript but didn't get a response, so I'll try here. I am using ASP.NET and I have a datagrid. One of the columns in my grid is all checkboxes. When the...
1
by: a developer | last post by:
i have a datagrid in which there is a template coulmn i have taken... which has template column in first column as checkbox in its header as well as item template also....now i need the...
1
by: David McCormick | last post by:
I have been scouring the message boards before I posted this question hoping to find an answer regarding datagrids and their behaviour after a sort command has been invoked. What I am trying to...
2
by: Mortar | last post by:
i have a datagrid with 2 columns. the 1st column contains an id which will be used by the database for the selected checkbox records. the 2nd column is a template column containing a server...
5
by: magmo | last post by:
Hi I have a datagrid that have checkboxes added to it and there is also a button that I want to use as a check what rows has been selected in the datagrid. But when I use this piece if code...
2
by: drakuu | last post by:
Hi guys, I created DataGrid with few checkboxes. I want to bind the checkboxes and check them if they match a string in a database. An if statement would look something like this: if...
0
by: shameem | last post by:
hi 2 all, my question is how to delete the records by using checkboxes in datagrid. pls give reply to my question.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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
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
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,...

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.