Adding a listitem to a table cell

Discussion in 'ASP .Net' started by Hong Yip, May 24, 2005.

  1. Hong Yip

    Hong Yip Guest

    Hi Everyone,

    I have an array of checkboxlist. Everything works prefectly fine until I
    start working on the "presentation" view. I am not able to "insert" a
    checkbox item to a table cell.

    Something like that,

    TableCell TCell = new TableCell();

    TCell.Control.Add( .....);

    Is there a way to add the list item into a table cell?

    Thanks!


    Regards,
    Hong Yip
     
    Hong Yip, May 24, 2005
    #1
    1. Advertisements

  2. Hong Yip

    Brock Allen Guest

    I might be missing your question, but you can do this:

    TableCell cell = new TableCell();
    CheckBox cb = new CheckBox();
    cell.Controls.Add(cb);
    MyTable.Rows[SomeRow].Cells.Add(cell);

    Since you're dynamically creating the control, you'll have to recreate it
    upon every postback if you want it to retain its state.
     
    Brock Allen, May 24, 2005
    #2
    1. Advertisements

  3. Thanks for Brock's suggestions.

    Hi Hong,

    As Brock has mentioned, we can dynamically create individual web controls
    and add them in a TableCell. Also, I'm not sure whether what you want is to
    add a ListItem into a TableCell? If so, I'm afraid this is not allowed
    since ListItem are not a WebControl ,they must be added into an existing
    ListControl. For example, we should generate a DropDownList or ListBox
    control and programmly add listItem (or through databinding) to fill them ,
    then add the DropDownList or ListBox into Table Cell.

    Please feel free to post here if there're any further questions. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], May 25, 2005
    #3
  4. Hong Yip

    Hong Yip Guest

    Hi Brook & Steven Cheng

    Thanks for the reply.

    Yes, Brook, What I really want to do is to add a listitem into a TableCell.
    Reason why I am putting into a TableCell is to 'tidy up' the presentation
    view of my array of checkboxlist. I guess I have to look at my data
    structure architecture to see if I can change it the way Brook has suggested
    it.


    Regards,
    Hong Yip
     
    Hong Yip, May 25, 2005
    #4
  5. OK. If there're any further questions or anything else we can help, please
    feel free to post here.

    Good Luck!

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], May 26, 2005
    #5
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.