SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    May 2006
    Posts
    457
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ckeckbox repeater

    HI all, im trying to create a checkbox repeater, that will be displayed within a tablecell.

    Code:
            Repeater repeater = new Repeater();
            ArrayList details = new ArrayList();
            details.Add("2");
            repeater.DataSource = details;
            repeater.DataBind();
    
    TableCell tablecell = new TableCell();
    tablecell.Controls.Add(repeater);
    tablerow.Cells.Add(tablecell);
    How can i go about telling the repeater each element added in the ArrayList will be a checkbox?

    In the tabelcell nothing will be outputted, am I not adding the repeater to the cell correctly?

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Use the checkboxlist control; that is exactly what it is there for.

    I would also highly recommend using the front-end pages (.aspx/.ascx files) to create the html framework and then databind to that rather than creating your display objects in codebehind.

  3. #3
    SitePoint Evangelist
    Join Date
    May 2006
    Posts
    457
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I ahve looked at using the checkboxlist control, however I didnt think it would be suitable for the following reasons:

    1. Unable to add a new checkbox to the checkboxlist with an ID and no text.
    i.e. all i want to appear is the checkbox but I do want to be able to hold an ID. Is there any way of adding the text (show below) but enable it to be hidden?
    Code:
    CheckBoxList detailslist = new CheckBoxList();
    detailslist.Items.Add("text");
    2. Unable to add the checkboxlist to a table column. I have a table defined:
    Code:
    Table alerttable = new Table();
            TableRow row = new TableRow();
    
            //HEADINGS
            TableCell cell = new TableCell();
            cell.Text = "<b>Alert Title</b>";
            row.Cells.Add(cell);
    
            cell = new TableCell();
            cell.Text = "<b>Priority</b>";
            row.Cells.Add(cell);
    
            cell = new TableCell();
            cell.Text = "<b>Action Date</b>";
            row.Cells.Add(cell);
    
    alerttable.Rows.Add(row);
    
                        cell = new TableCell();
                        cell.Text = "1";
                        row.Cells.Add(tablecell);
    
                        cell = new TableCell();
                        cell.Text = "4";
                        row.Cells.Add(tablecell);
    
                        cell = new TableCell();
                        cell.Text = "3";
                        row.Cells.Add(tablecell);
    
    alerttable.Rows.Add(row);
    I cant add an additional column to this table that contains the checkboxlist.

  4. #4
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Textless checkbox:

    Code:
    ListItem li=new ListItem();
    li.Name=string.Empty;
    li.Value=MyIDValue;
    As for the table thing: first, you really should not be creating the table in codebehind but rather using declarative markup. You will be much happier in the end. And why can't you add a checkbox list to any of the cells? I have never tried, but there is no reason why you cannot add it like you could add any other control.

  5. #5
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I have looked into this, you can use Placeholder to render the table control

    CheckBoxList chkList = new CheckBoxList();

    Table table = new Table();
    TableRow tableRow = new TableRow();

    chkList.Items.Add("2");

    TableCell tableCell = new TableCell();
    tableCell.Controls.Add(chkList);
    tableRow.Cells.Add(tableCell);
    table.Rows.Add(tableRow);

    placeholder1.Controls.Add(table);



    It is showing a checkbox in the table cell. if you want to show check box without any text then add the like that

    chkList.Items.Add("");


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •