Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to display only the fist 50 characters of a record, then click to expand the table

Posted on 2016-10-04
4
65 Views
Last Modified: 2016-10-05
Hi Experts,

On my web page I'm displaying database records. One column is named "Comments" and it is varchar(MAX) data type in the SQL Server database.

<td align="left"><%=rs("Comments")%></td>

The table cell becomes too big when the Comments field contains too many characters. Is it possible to display only the first 50 characters of each record, then when the TD is clicked, it expands and shows the full record? When a different record is clicked it collapses to show the first 50 characters only.

My page is written is Classic ASP.

Thank you for your help.
0
Comment
Question by:romsom
  • 2
  • 2
4 Comments
 
LVL 33

Accepted Solution

by:
Big Monty earned 500 total points
ID: 41828661
i came across this example while looking for a solution, seems to do what you want with regards to expanding/collapsing rows, although it doesn't enforce the rule of expanding one row at a time, but that can be added later:

http://jsfiddle.net/mfwYS/

your code would look along the lines of:

<table>
<%
dim comments, previewComments
do while not rs.EOF
    comments = rs("comments")
     previewComments = Left( comments, 2 )
%>
    <tr><td><%=previewComments%></td></tr>
    <tr><td><%=comments%></td></tr>
<%
     rs.MoveNext
loop
%>
    
</table>

Open in new window


this is a very quick and dirty example, you'll need to modify it to meet your needs, but you should get the gist of it
0
 

Author Comment

by:romsom
ID: 41828918
Thank you very much Monty!
I'm afraid I will need some more help. I'm struggling to make the page appear with the short version of the Comments field. My goal is to expand it when clicked. I don't want to click the table header because that is supposed to sort the records. I would like the short Comments and long Comments alternate when the TD is clicked. Please take a look at the complete code of my page. How should I modify it in order to achieve my goal? I tried changing the colspan and the p to B and I, but whenever I placed those tags in my table the content just disappeared, but the TD was still visible.
<!-- #include virtual="/Connections/Authentication.asp" -->
<%
if request.querystring("sort")<>"" then
   sort=request.querystring("sort")
else
   sort="ID desc"
end if

set rs = Server.CreateObject("ADODB.Recordset")
rs.CursorLocation = 3  ' adUseClient

rs.Open "SELECT * FROM Complaints ORDER BY " & sort & " " & request.querystring("order"), conn

rs.PageSize = 10
intPageCount = rs.PageCount

Select Case Request("Action")
	case "<<"
		intpage = 1
	case "<"
		intpage = Request("intpage")-1
		if intpage < 1 then intpage = 1
	case ">"
		intpage = Request("intpage")+1
		if intpage > intPageCount then intpage = IntPageCount
	Case ">>"
		intpage = intPageCount
	case else
		intpage = 1
end select
%>
<html>
<head>
<title></title>
<link rel="stylesheet" href="/Scripts/Styles.css" type="text/css" />
<script type="text/javascript" src="/jquery/js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="/jquery/js/jquery-ui-1.8.13.custom.min.js"></script>

<script type="text/javascript">
$(function() {
    $("td[colspan=3]").find("p").hide();
    $("table").click(function(event) {
        event.stopPropagation();
        var $target = $(event.target);
        if ( $target.closest("td").attr("colspan") > 1 ) {
            $target.slideUp();
        } else {
            $target.closest("tr").next().find("p").slideToggle();
        }                    
    });
});
</script>
</head>
<body>

<table align="center" class="border">
<tr>
<td >
<%if request.querystring("order") = "DESC" then%>
<a href="Disability1.asp?sort=CustName&order=ASC">CustomerName</a>
<%else%>
<a href="Disability1.asp?sort=CustName&order=DESC">CustomerName</a>
<%end if%>
</td>
<td align="center" class="hand">
<%if request.querystring("order") = "DESC" then%>
<a href="Disability1.asp?sort=Comments&order=ASC">Comments</a>
<%else%>
<a href="Disability1.asp?sort=Comments&order=DESC">Comments</a>
<%end if%>
</td>

</tr>
<%
rs.AbsolutePage = intPage
For intRecord = 1 To rs.PageSize
%>

<%
dim comments, previewComments

    comments = rs("comments")
     previewComments = Left( comments, 20 )
%>
<tr>

<td class="border"><%=rs("CustName")%></td>

<td class="border"><b><%=previewComments%></b></td>
<td class="border"><i><%=comments%></i></td>


</tr>

<%
rs.MoveNext
If rs.EOF Then Exit For
Next
rs.Close
set rs = Nothing
Conn.Close
set Conn = Nothing
%>
</table>
 
 </body>
 </html>




    

Open in new window

0
 
LVL 33

Expert Comment

by:Big Monty
ID: 41828939
I'll have a look at this tomorrow
1
 

Author Closing Comment

by:romsom
ID: 41830751
Thank you very much, I figured out the rest. It's actually a better solution than I was hoping for.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 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