473,320 Members | 1,814 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,320 software developers and data experts.

show check box in repeater based on database value

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
3 2718
You can move the same code to simple function to determin if the check box
will be visible or not

<asp:CheckBox Visible='<%#VisibleYesNo(DataBinder.Eval(Container .DataItem,
"bThisUserHasIt").ToString())%>' ID="chk" Runat="server"></asp:CheckBox>

Please note the

Visible='<%#VisibleYesNo(DataBinder.Eval (Container.DataItem,
"bThisUserHasIt").ToString())%>'

the VisibleYesNo funtion would look like

protected bool VisibleYesNo (string val)
{
if(val=="0")
return(true);

return(false);
}

"Imran Aziz" wrote:
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
You could make use of the Finbyvalue method and loop through the checkboxes.
Or create a function VisibleYesorNo function as adviced.
Patrick
"Imran Aziz" <im***@tb2.net> wrote in message
news:eV**************@tk2msftngp13.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
Wonderful thanks a lot that worked great.
Imran
"Sreejith Ram" <Sr*********@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
You can move the same code to simple function to determin if the check box
will be visible or not

<asp:CheckBox
Visible='<%#VisibleYesNo(DataBinder.Eval(Container .DataItem,
"bThisUserHasIt").ToString())%>' ID="chk" Runat="server"></asp:CheckBox>

Please note the

Visible='<%#VisibleYesNo(DataBinder.Eval (Container.DataItem,
"bThisUserHasIt").ToString())%>'

the VisibleYesNo funtion would look like

protected bool VisibleYesNo (string val)
{
if(val=="0")
return(true);

return(false);
}

"Imran Aziz" wrote:
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

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

Similar topics

0
by: Jim French | last post by:
I have a page that takes a comma delimited string and needs to bind to a Repeater control. The string is split into an Array, and each value is put into a DataBase query via a For Each loop. The...
2
by: Alan Silver | last post by:
Hello, I have a form that contains a repeater. A simplified version of the ItemTemplate is shown below (air code)... <br><asp:Literal id="litID" runat="server" /> <br><asp:TextBox id="txtQty"...
4
by: sck10 | last post by:
Hello, I have a repeater that is bound to a SQL Server table. I would like to place a summary in the footer for the item count and product cost. I have two fields. One for the product name...
9
by: Jaybuffet | last post by:
my aspx has something like this <asp:Repeater id="Repeater1" runat="server"> <ItemTemplate> <mycontrol:ctl id="ctlId" obj='<%# Container.DataItem %>' showItem="true"/> </ItemTemplate>...
4
by: Marc Llenas | last post by:
Hi there, I have a repeater that returns x rows from a main table. I need to display some info stored on a secondary table that is linked to the main using a one-to-many relationship. ...
0
by: erin.sebastian | last post by:
Hello All, I have created a web page. At the top of the page there are 4 links; upon clicking on one of the links it brings up the left hand side menu, it's a repeater that loops through items...
1
by: Sully | last post by:
Hi Everyone, I am pretty new to coding in .net and need some help in showing and hiding information from a repeater control. I am calling a list of FAQ's from a Database and display both the...
7
by: | last post by:
I have what's probably a simple page lifecycle question related to dynamically evaluating values that are placed by a repeater and dynmically placing user controls that use those values. I'm...
5
by: Brad Baker | last post by:
I am trying to make a "tabbed" interface by iterating through a dataset with a conditional statement. For example: ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.