RadioButtonList - need horizontal instead of vertical

Posted on 2005-05-11
Last Modified: 2009-07-29
This code makes the radio button list go down instead of across.
I fill the RBList from a data table - it's like a multiple question survey where the user selects from 1 to 10 as an answer by clicking corresponding RB.  Where do I make it go across the page?

      Row = addRow(CustomTable, null);
      addCell(Row, tdclass);
      addLabel(Row.Cells[1], Heading);
      addCell(Row, tdclass);

         if (strSelectionsSourceTable != "")
            addRadioButtons(Row.Cells[2], strSelectionsSourceTable, strParmValue, id);

      private void addRadioButtons(TableCell oCell, string strSelectionsSourceTable, string strParmValue, string ID)
            RadioButtonList vList = buildListForV(strSelectionsSourceTable, strParmValue);
            vList.ID = ID;

      private RadioButtonList buildListForV(string strSelectionsSourceTable, string strSelected)
            object [] dtVKRecords;
            DataTable dtVRecords;
            string sql = "SELECT * FROM " + strSelectionsSourceTable+" WHERE RecType='K1'";
            SqlConnection con = dbAccess.getSqlConnection("xxxxx");
            dtVKRecords = dbAccess.readFirstRecord(con, sql);
            dtVRecords = dbAccess.getDataTable(con, strSelectionsSourceTable, sql);

            string strPk    = null;
            string strPk2 = null;
            string strDesc1 = null;
            string strDesc2 = null;
            strPk = dtVKKey;
            strDesc1 = strPk;
            RadioButtonList result = new RadioButtonList();
            foreach (DataRow row in dtVRecords.Rows)
                  string sLabel = "";
                  sLabel = row[strDesc1].ToString();
                  ListItem newItem = new ListItem(sLabel, row[strPk].ToString());
                  sLabel = sLabel.Substring(0,50);
                  newItem = new ListItem(sLabel, row[strPk].ToString());
            return result;
Question by:dcass
    LVL 2

    Expert Comment

    you're are adding all radio button to one cell only, what problably is happening is that the table is not resizing in the way you want, instead of raising with of cell is raising height.

    you can solve the problem by adding one radio button at a time to different cells in the same line.

    Author Comment

    I tried it but it didn't help.

    Author Comment

    I dont' think I did it right -

                result.Items.Add(newItem);      (from above)
                addCell(Row, tdclass);
                    return result;

          private TableCell addCell(TableRow oRow, string cssClass)
                      TableCell newCell = new TableCell();
                      if (null != cssClass)
                            newCell.CssClass = cssClass;

                      return newCell;

    Accepted Solution

    The answer was :
                      result.RepeatDirection = RepeatDirection.Horizontal;

    Please close this.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Suggested Solutions

    Article by: Ivo
    Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
    Article by: Ivo
    C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    This video discusses moving either the default database or any database to a new volume.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now