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

Discussion in 'ASP .Net' started by Imran Aziz, Aug 11, 2005.

  1. Imran Aziz

    Imran Aziz Guest

    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.
     
    Imran Aziz, Aug 11, 2005
    #1
    1. Advertising

  2. Imran Aziz

    Arjen Guest

    Add your checkbox with the visable attribute like this:

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

    Hope this helps,
    Arjen


    "Imran Aziz" <> schreef in bericht
    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\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.
    >
    >
    >
     
    Arjen, Aug 11, 2005
    #2
    1. Advertising

  3. 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" <> 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\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.
    >
    >
    >
     
    Grant Merwitz, Aug 11, 2005
    #3
  4. Imran Aziz

    Imran Aziz Guest

    understood thanks a lot Grant :)
    Imran
    "Grant Merwitz" <> wrote in message
    news:e$...
    > 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" <> 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\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.
    >>
    >>
    >>

    >
    >
     
    Imran Aziz, Aug 11, 2005
    #4
  5. Imran Aziz

    Imran Aziz Guest

    Thanks Arjen this is a quick solution and works great !
    Imran.

    "Arjen" <> wrote in message
    news:ddf7je$nce$1.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" <> schreef in bericht
    > 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\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.
    >>
    >>
    >>

    >
    >
     
    Imran Aziz, Aug 11, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thomas R

    Checkbox inside a repeater control..

    Thomas R, Nov 20, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    14,285
    Thomas R
    Nov 21, 2003
  2. =?Utf-8?B?QW5kcmV3?=

    capturing checkbox.checked in repeater control

    =?Utf-8?B?QW5kcmV3?=, Aug 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,870
    =?Utf-8?B?QW5kcmV3?=
    Aug 23, 2005
  3. c_shah
    Replies:
    5
    Views:
    1,157
    CitrusMotors.com
    Jun 15, 2007
  4. Brian Miller
    Replies:
    6
    Views:
    750
    Brian Miller
    Nov 18, 2004
  5. Imran Aziz

    checkbox value attribute in checkbox control ?

    Imran Aziz, Aug 6, 2005, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    234
    Imran Aziz
    Aug 8, 2005
Loading...

Share This Page