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

choosing to display or not to display a checkbox in repeater control.

Hello All,
I display a list of entries with a checkbox against them using a
repeater control bound to a database table. Based on the value of database
table I want to either show the checkbox for a row or not to show, how do I
accomplish that using a repeater control ?
Should I do something like this

<%if (((DataRowView)Container.DataItem)["bThisUserHasIt"] == 0)

{ %><asp:CheckBox ID="chkBookMarkID" text='<%#
((DataRowView)Container.DataItem)["nBookMarkID"] %>' runat="server"
ForeColor="White" Font-Size="1px" /<%} %>
(this one does not work , but I am thinking it might be possible to do it
like that, get this error, Error 2 The name 'Container' does not exist in
the current context
C:\Inetpub\wwwroot\allenandovery\bookmarks\recentb ookmarks.aspx 24 35
C:\...\allenandovery\
)

or is there a better way to do it, checking and specifying the value in code
behind?
Thanks a lot for your support.
Imran.

Nov 19 '05 #1
4 2691
Add your checkbox with the visable attribute like this:

visable='<# ((DataRowView)Container.DataItem["bThisUserHasIt"] ==
0)?"true":"false"'

Hope this helps,
Arjen
"Imran Aziz" <im***@tb2.net> schreef in bericht
news:eg**************@TK2MSFTNGP09.phx.gbl...
Hello All,
I display a list of entries with a checkbox against them using a
repeater control bound to a database table. Based on the value of database
table I want to either show the checkbox for a row or not to show, how do
I
accomplish that using a repeater control ?
Should I do something like this

<%if (((DataRowView)Container.DataItem)["bThisUserHasIt"] == 0)

{ %><asp:CheckBox ID="chkBookMarkID" text='<%#
((DataRowView)Container.DataItem)["nBookMarkID"] %>' runat="server"
ForeColor="White" Font-Size="1px" /<%} %>
(this one does not work , but I am thinking it might be possible to do it
like that, get this error, Error 2 The name 'Container' does not exist in
the current context
C:\Inetpub\wwwroot\allenandovery\bookmarks\recentb ookmarks.aspx 24 35
C:\...\allenandovery\
)

or is there a better way to do it, checking and specifying the value in
code
behind?
Thanks a lot for your support.
Imran.

Nov 19 '05 #2
The method you are trying will work with the right syntax

But i prefer to push the functionality to the code behind leaving as much
logic out of the UI as possible.

This can be done calling a method that does the functionality you've written
there,

or what i more prefer - using the ItemDataBound event

DataLists, Grids and Repeaters all have a OnItemDataBound event, where item
by item you can perform some processing.
In this case, you can determine - item by item - whether to show or hide
your checkbox.

Just ensure in that ItemDataBound event, you are checking that your not in
the header or footer.
do a check like
private void DataList_OnItemDataBound(System.Object sender,
DataItemEventArgs e)
{
if(e.Item.ItemTemplate != ItemTemplate.Header && e.Item.ItemTemplate
!= ItemTemplate.Footer)
{
//Do you logic to remove checkbox here
}
}

HTH

"Imran Aziz" <im***@tb2.net> wrote in message
news:eg**************@TK2MSFTNGP09.phx.gbl...
Hello All,
I display a list of entries with a checkbox against them using a
repeater control bound to a database table. Based on the value of database
table I want to either show the checkbox for a row or not to show, how do
I
accomplish that using a repeater control ?
Should I do something like this

<%if (((DataRowView)Container.DataItem)["bThisUserHasIt"] == 0)

{ %><asp:CheckBox ID="chkBookMarkID" text='<%#
((DataRowView)Container.DataItem)["nBookMarkID"] %>' runat="server"
ForeColor="White" Font-Size="1px" /<%} %>
(this one does not work , but I am thinking it might be possible to do it
like that, get this error, Error 2 The name 'Container' does not exist in
the current context
C:\Inetpub\wwwroot\allenandovery\bookmarks\recentb ookmarks.aspx 24 35
C:\...\allenandovery\
)

or is there a better way to do it, checking and specifying the value in
code
behind?
Thanks a lot for your support.
Imran.

Nov 19 '05 #3
understood thanks a lot Grant :)
Imran
"Grant Merwitz" <gr***@workshare.com> wrote in message
news:e$**************@TK2MSFTNGP10.phx.gbl...
The method you are trying will work with the right syntax

But i prefer to push the functionality to the code behind leaving as much
logic out of the UI as possible.

This can be done calling a method that does the functionality you've
written there,

or what i more prefer - using the ItemDataBound event

DataLists, Grids and Repeaters all have a OnItemDataBound event, where
item by item you can perform some processing.
In this case, you can determine - item by item - whether to show or hide
your checkbox.

Just ensure in that ItemDataBound event, you are checking that your not in
the header or footer.
do a check like
private void DataList_OnItemDataBound(System.Object sender,
DataItemEventArgs e)
{
if(e.Item.ItemTemplate != ItemTemplate.Header &&
e.Item.ItemTemplate != ItemTemplate.Footer)
{
//Do you logic to remove checkbox here
}
}

HTH

"Imran Aziz" <im***@tb2.net> wrote in message
news:eg**************@TK2MSFTNGP09.phx.gbl...
Hello All,
I display a list of entries with a checkbox against them using a
repeater control bound to a database table. Based on the value of
database
table I want to either show the checkbox for a row or not to show, how do
I
accomplish that using a repeater control ?
Should I do something like this

<%if (((DataRowView)Container.DataItem)["bThisUserHasIt"] == 0)

{ %><asp:CheckBox ID="chkBookMarkID" text='<%#
((DataRowView)Container.DataItem)["nBookMarkID"] %>' runat="server"
ForeColor="White" Font-Size="1px" /<%} %>
(this one does not work , but I am thinking it might be possible to do it
like that, get this error, Error 2 The name 'Container' does not exist in
the current context
C:\Inetpub\wwwroot\allenandovery\bookmarks\recentb ookmarks.aspx 24 35
C:\...\allenandovery\
)

or is there a better way to do it, checking and specifying the value in
code
behind?
Thanks a lot for your support.
Imran.


Nov 19 '05 #4
Thanks Arjen this is a quick solution and works great !
Imran.

"Arjen" <bo*****@hotmail.com> wrote in message
news:dd**********@news6.zwoll1.ov.home.nl...
Add your checkbox with the visable attribute like this:

visable='<# ((DataRowView)Container.DataItem["bThisUserHasIt"] ==
0)?"true":"false"'

Hope this helps,
Arjen
"Imran Aziz" <im***@tb2.net> schreef in bericht
news:eg**************@TK2MSFTNGP09.phx.gbl...
Hello All,
I display a list of entries with a checkbox against them using a
repeater control bound to a database table. Based on the value of
database
table I want to either show the checkbox for a row or not to show, how do
I
accomplish that using a repeater control ?
Should I do something like this

<%if (((DataRowView)Container.DataItem)["bThisUserHasIt"] == 0)

{ %><asp:CheckBox ID="chkBookMarkID" text='<%#
((DataRowView)Container.DataItem)["nBookMarkID"] %>' runat="server"
ForeColor="White" Font-Size="1px" /<%} %>
(this one does not work , but I am thinking it might be possible to do it
like that, get this error, Error 2 The name 'Container' does not exist in
the current context
C:\Inetpub\wwwroot\allenandovery\bookmarks\recentb ookmarks.aspx 24 35
C:\...\allenandovery\
)

or is there a better way to do it, checking and specifying the value in
code
behind?
Thanks a lot for your support.
Imran.


Nov 19 '05 #5

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

Similar topics

2
by: Thomas R | last post by:
Is is possible? In VS.NET 2003, Binding data to the repeater is easy, but when I try to add an ASP:checkbox to the .aspx page, the designer won't recognize it, hence the code view doesn't allow...
3
by: Jack Turnbull | last post by:
Hi, I have a Checkbox in a Repeater set to AutoPostBack = true. I have pointed OnCheckedChanged to a Sub but it doesn't fire. If I move the checkbox out of the Repeater it fires! Any ideas? Thanks
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...
1
by: tolaskram | last post by:
We're developing an ASP.NET 2.0 (C#) application that needs to display array data in a tabular format. Some might say "simply use the GridView control," which might work for us. But, we have a...
8
by: Alan Silver | last post by:
Hello, I have a repeater that has code like this... <ItemTemplate> <asp:CheckBox ID="chkDelete" Text="" RunAt="server"/> .... other stuff goes here </ItemTemplate> There is a button below...
2
by: RichardH | last post by:
Hi, I have x number of table rows that all should have a checkbox and a dropdownlist on each row. The checkbox could be checked and the dropdown should contain y number of values that are...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
0
by: Keith | last post by:
I have a repeater control that contains a HeaderTemplate and an ItemTemplate. Each item contains a checkbox with an ID of chkReconciled, and the header contains a single checkbox with an ID of...
5
by: c_shah | last post by:
using VB.net (2005) ASP.net 2.0 I have a repeater control with the item template, in the item template I have two checkboxes How to capture event When user checks the checkboxes? What event...
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
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.