471,092 Members | 1,784 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,092 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 2605
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Thomas R | last post: by
3 posts views Thread by Jack Turnbull | last post: by
2 posts views Thread by RichardH | last post: by
5 posts views Thread by c_shah | last post: by

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.