show check box in repeater based on database value

I

Imran Aziz

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.
 
G

Guest

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);
}
 
P

Patrick.O.Ige

You could make use of the Finbyvalue method and loop through the checkboxes.
Or create a function VisibleYesorNo function as adviced.
Patrick
 
I

Imran Aziz

Wonderful thanks a lot that worked great.
Imran
Sreejith Ram said:
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 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top