ASP.NET Substring

T

Tahir

hi,
i am programming a website using ASP.NET 2.0 and SQL 2005 and serving the
last five members via DataList containing a HyperLink like this code:
<asp:HyperLink ID="firmaHyperLink" runat="server" NavigateUrl='<%#
Eval("firmId", "~/Firma.aspx?firmId={0}") %>' Text='<%# Eval("name", "{0}")
%>' ></asp:HyperLink>
i have a problem that "name" variable may be too long so how can i substring
it? very glad if a sample code :)
 
C

Cowboy \(Gregory A. Beamer\)

You can always do the binding of this field in code behind using the Row
Data Binding event. This allows you to evaluate the value and do whatever
you want before binding it.

If that is not acceptable, you can bind back to a routine that does the work
for you. Just pass the entire Eval back to the routine.
 
Joined
Aug 9, 2007
Messages
4
Reaction score
0
try this

Code:
private void dataList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
      if( (e.Item.ItemType == ListItemType.Item) || ( e.Item.ItemType == ListItemType.AlternatingItem))
      {
            HyperLink hyplnk = (HyperLink)e.Item.FindControl("firmaHyperLink");
            if (hyplnk.Text.length > 20 )
            {
                 hyplnk.Text = hyplnk.Text.Substring(0,20);
            }
      }
}
 

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

Ask a Question

Members online

Forum statistics

Threads
474,176
Messages
2,570,950
Members
47,501
Latest member
log5Sshell/alfa5

Latest Threads

Top