PC Review


Reply
Thread Tools Rate Thread

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

 
 
Imran Aziz
Guest
Posts: n/a
 
      11th Aug 2005
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\recentbookmarks.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.



 
Reply With Quote
 
 
 
 
Arjen
Guest
Posts: n/a
 
      11th Aug 2005
Add your checkbox with the visable attribute like this:

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

Hope this helps,
Arjen


"Imran Aziz" <(E-Mail Removed)> schreef in bericht
news:(E-Mail Removed)...
> 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\recentbookmarks.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.
>
>
>



 
Reply With Quote
 
Grant Merwitz
Guest
Posts: n/a
 
      11th Aug 2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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\recentbookmarks.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.
>
>
>



 
Reply With Quote
 
Imran Aziz
Guest
Posts: n/a
 
      11th Aug 2005
understood thanks a lot Grant
Imran
"Grant Merwitz" <(E-Mail Removed)> wrote in message
news:e$(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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\recentbookmarks.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.
>>
>>
>>

>
>



 
Reply With Quote
 
Imran Aziz
Guest
Posts: n/a
 
      11th Aug 2005
Thanks Arjen this is a quick solution and works great !
Imran.

"Arjen" <(E-Mail Removed)> wrote in message
news:ddf7je$nce$(E-Mail Removed)...
> Add your checkbox with the visable attribute like this:
>
> visable='<# ((DataRowView)Container.DataItem["bThisUserHasIt"] ==
> 0)?"true":"false"'
>
> Hope this helps,
> Arjen
>
>
> "Imran Aziz" <(E-Mail Removed)> schreef in bericht
> news:(E-Mail Removed)...
>> 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\recentbookmarks.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.
>>
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checkbox Control - How to display a true or false value in the cellcontaining a checkbox Dave K Microsoft Excel Discussion 1 8th Sep 2010 08:31 PM
Adding a checkbox to a repeater control Doogie Microsoft ASP .NET 1 14th Jun 2007 08:35 PM
Loop to display nested items in Repeater control? parsifal Microsoft ASP .NET 4 9th Mar 2007 02:52 PM
CheckBox List control Display Steven Microsoft C# .NET 0 31st Mar 2005 08:20 PM
Use we control to display data in Repeater Steve Microsoft ASP .NET 0 10th Jan 2004 12:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:28 AM.