Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 18th, 2008, 07:15 PM
Authorized User
 
Join Date: Jan 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Field from a database

 Hi

I am using itemtemplate of a gridview to display a value that i retrieve from database but the problem is that the text within that field is too long therefore i only want to take the first 40 character out of it. I done some searching and realize that have to do something with the Left() function but absolutely no idea how to get it done.

I am using vb.net and working in aspx....



Thanks in advance
 
Old March 18th, 2008, 10:45 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What is the contents of your item template?

-Peter
peterlanoie.blog
 
Old March 19th, 2008, 04:08 AM
Authorized User
 
Join Date: Jan 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

here is my code below:

-------------------------

   <ItemTemplate>
                                                 <img width=80 height="80" align="left" src='<%# Eval ( "SImageURL")%> '/>

                                                 <table>
                                                    <tr>
                                                      <td>
                                                         Â»
                                                         <a href='http://www.abc.com/<%# Replace(Eval("CategoryName")," ","-") %>/<%# Replace(Replace(Eval("Heading"),"'","")," ","-")%>.news/<%# Eval("ArticleID") %>'><%# eval("Heading") %></a>&nbsp;<br /><br />
                                                       </td>
                                                    </tr>
                                                    <tr>
                                                       <td>
                                                       <a href='http://www.abc.com/<%# Replace(Eval("CategoryName")," ","-") %>/<%# Replace(Replace(Eval("Heading"),"'","")," ","-")%>.news/<%# Eval("ArticleID") %>' class="greytext">&nbsp;&nbsp;&nbsp;READ MORE </a>
                                                        </td>
                                                     </tr>
                                                     <tr>
                                                        <td>&nbsp;&nbsp; Date : <%#Eval("ArticleDate")%> </td>

                                                     <%-- <td><%#Eval("ArticleDate")%></td>--%>
                                                       <%--<td>&nbsp;&nbsp;Dated: <%# Eval("ArticleDate") %></td>--%>
                                                    </tr>
                                                  </table>

                                                </ItemTemplate>
 
Old March 19th, 2008, 06:41 AM
Authorized User
 
Join Date: Mar 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

you have to do just like this :

<%# Left(Eval("fieldname"),40)%>

this will show only first 40 character of that field.

hope this will help you.

 
Old March 19th, 2008, 07:44 AM
Authorized User
 
Join Date: Jan 2008
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Many thanks yes its working
Just a little thing more

How can i add "...more" at the end, i tried different ways but keep getting different errors...

Many Thanks

 
Old March 19th, 2008, 10:01 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I don't know what value you want to truncate but you have lots of Replace calls in there so you should be able to easily add a string class method call to get just the beginning of the value. If you need to do some complex logic you can also create a protected method in your code-behind and call that method from the binding expression. Then the method can process the string as you need.

-Peter
peterlanoie.blog
 
Old March 20th, 2008, 06:17 AM
Authorized User
 
Join Date: Mar 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

if you want to add "..more" at the end of string then you need to do concatenate with string like this

 <%#Left(Eval("fieldname"), 40) & "...more"%>

thats it.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Need ONLY date in datetime field in Database Lucy SQL Server 2000 10 April 30th, 2007 09:20 AM
compare form field to database before submit chelle60 Javascript How-To 3 January 2nd, 2007 05:42 AM
Help submitting a field into a database jim b Classic ASP Basics 1 July 26th, 2006 09:32 PM
Validating a form field against a database microchip Classic ASP Basics 2 April 24th, 2004 04:07 PM
Determining the length of a database field john_reeve41 BOOK: Beginning ASP 3.0 2 February 26th, 2004 12:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.