![]() |
|
|
|||||||
![]() |
ASP Net - show check box in repeater based on database value |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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. Imran Aziz |
|
|
|
|
#2 |
|
Posts: n/a
|
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. > > > =?Utf-8?B?U3JlZWppdGggUmFt?= |
|
|
|
#3 |
|
Posts: n/a
|
You could make use of the Finbyvalue method and loop through the checkboxes.
Or create a function VisibleYesorNo function as adviced. Patrick "Imran Aziz" <> wrote in message news:... > 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. > > Patrick.O.Ige |
|
|
|
#4 |
|
Posts: n/a
|
Wonderful thanks a lot that worked great.
Imran "Sreejith Ram" <> wrote in message news:4C492987-EEC2-4BA8-BD25-... > 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. >> >> >> Imran Aziz |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| TRADING FEMALE CELEB INTERVIEWS ON DVD | stu | DVD Video | 1 | 05-26-2008 09:39 AM |
| DVD Verdict reviews: THE OPRAH WINFREY SHOW: 20TH ANNIVERSARY DVD COLLECTION and more! | DVD Verdict | DVD Video | 0 | 12-14-2005 09:14 AM |
| Classic Original Broadcasts Trading List - Updated ( w/o/c ) | porkys1982@sbcglobal.net | DVD Video | 0 | 12-05-2005 03:38 AM |
| Classic Original Broadcasts Trading List - Updated ( w/o/c ) | porkys1982@sbcglobal.net | DVD Video | 0 | 11-19-2005 04:46 PM |
| Original Airings : The A-Team , M*A*S*H , Taxi , Barney Miller , WKRP | porkys1982@sbcglobal.net | DVD Video | 0 | 08-15-2005 03:09 AM |