Newbie constraints and how to

  • I am using a recordset to populate combo boxes for a webpage, but I want to make all boxes the same length. So far the only means I have found is to create a 'dummy' "- Please select - " list value that is the same for all combo boxes. However when pulling results from the DB that are longer than my dummy entry the combo box stretches to accommodate and this throws my alignments off.

    Is there an easy way to either specify the length in the ASP code, or can the DB limit the length of entries into the feilds to 30 characters?

    Datatype is text and so 16bytes.

  • 2 suggestions :

    1) Put all of the elements in your page into a hidden table. That way the combo

    boxes, text boxes width won't matter. Everything will be align-able using the

    table's properties.

    2) (LESS Preferred) Use Left(..., 30) on your values before displaying them.

    The 1st technique is the most widely used to get web pages to layout in an

    orderly fashion.

    Tim C.

    //Will write code for food

    One Windows to rule them all, One Windows to find them,

    One Windows to bring them all and in the darkness bind them

    In the Land of Microsoft where the Shadows lie.


    Tim C //Will code for food

  • Example for #1 :

    
    
    <html>
    <head>
    <title>Foo</title>
    </head>
    <body>
    <TABLE id="Table1" cellSpacing="0" cellPadding="0" align="center" border="0">
    <TR>
    <TD noWrap align="left">This is some arbitrary text for column 1</TD>
    <TD noWrap align="left"><SELECT ID="Select1" NAME="Select1">
    <OPTION value="1">Value 1</OPTION>
    <OPTION value="2">Value 2 with some really long text. Longer than 30 chars</OPTION>
    <OPTION value="3">Value 3</OPTION>
    <OPTION value="4">Value 4</OPTION>
    </SELECT>
    </TD>
    </TR>
    <TR>
    <TD noWrap align="left">column 2</TD>
    <TD noWrap align="left"><SELECT ID="Select2" NAME="Select1">
    <OPTION value="1">Value 1</OPTION>
    <OPTION value="2">Value 2 with some really long text. Longer than 30 chars</OPTION>
    <OPTION value="3">Value 3</OPTION>
    <OPTION value="4">Value 4</OPTION>
    </SELECT>
    </TD>
    </TR>
    <TR>
    <TD noWrap align="left">text for column 3</TD>
    <TD noWrap align="left"><SELECT ID="Select3" NAME="Select1">
    <OPTION value="1">Value 1</OPTION>
    <OPTION value="2">Value 2 with some really long text. Longer than 30 chars</OPTION>
    <OPTION value="3">Value 3</OPTION>
    <OPTION value="4">Value 4</OPTION>
    </SELECT>
    </TD>
    </TR>
    </TABLE>
    </body>
    </html>

    Save into a text file and rename it Foo.html, and open with Internet Exploder, or NetScrape.

    Tim C.

    //Will write code for food

    One Windows to rule them all, One Windows to find them,

    One Windows to bring them all and in the darkness bind them

    In the Land of Microsoft where the Shadows lie.


    Tim C //Will code for food

  • First of all, I believe this is a client issue (representation of data) and not a database issue. I don't think it is possible to limit the size of a combobox. The solution is to trim the results that you get from the recordset. Use the appropriate string function for your environment.

    What I don't get either is the data type you propose for your column. The TEXT data type is used for large chuncks of text (larger than 8000 characters), not for small pieces of text. You should use either CHAR or VARCHAR, depending on the type of data you are storing. Check Books Online for more info.

    (And for completeness, if you want to limit the length of the text you retrieve from the database, use the T-SQL function SUBSTRING(field_name, 1, 30))

  • Thanks for the advice.

    I understand the suggestion about tables being used to constrain the combo boxes, but if the length of the text to be displayed exceeds the length provided for in the table then the table stretches to accommodate - resulting in my other columns being pushed around and out of alignment.

    This is the method I have been trying to use.

    Trimming the results of the recordset seems to offer more promise - but might result in an option that is incomprehensible to the end user.

    Though i have set validation rules that specify entries to the DB are limited to 30 characters, so all future results will 'fit' with my arangement, I haven't worked out how i can constrain the existing DB entry's. Or block later users entering directly into the DB.

    I know how to limit the length in MS Access, but i'm new to SQL2k and it isn't obvious to me, yet, how to achieve the same result.

    I would like to add that I didnt design the DB, I have been handed it and the task of creating a web interface for it so I cant pass the task over to anyone else.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply