Click to See Complete Forum and Search --> : LinkButton HowTo wrap the text


balda
02-15-2007, 12:11 PM
Hello ALL,
I have a small problem using LinkButton control.
I have to setup linkbutton text to have width no more than 100px and everything that goes beyond it should just wrap up the text.
I was trying to do so using width for this server control; put it inside single table row where I specify the width, nothing helps, it still goes as a single line when I run web page.
Is any soultion available to wrap linkbutton text on the web page for desired width?
I am suing ASP.net 2.0 in VS2005
Thank you,
balda

lmf232s
02-15-2007, 01:27 PM
Setting the width of the link button works for me.


<asp:Linkbutton id="lnkTest"
runat="server"
width="100px"
text="This is a test to see if i can get this code to wrap or not by setting the width of the link button to a width of 100px. Lets see if it works"/>

balda
02-15-2007, 02:53 PM
I agree, width should work, I don't know why it keeps extended when I specified particular width, really weird.
I am using this linkbutton inside of ItemTemplate column in DataList Control, if it makes any difference. so when my linkbutton too long my Datalist cell also got extended for the lenght of linkbutton lenght. :-(

lmf232s
02-15-2007, 04:16 PM
You need to post some code. Im not sure what problem your having.
Here is another example using a datalist that does exaclty what you want.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Create DataTable
Dim dt As DataTable = New DataTable("MyTest")
dt.Columns.Add("Column1", Type.GetType("System.String"))
dt.Columns.Add("Column2", Type.GetType("System.String"))
dt.Columns.Add("Column3", Type.GetType("System.String"))
dt.Columns.Add("Column4", Type.GetType("System.String"))

'Add Row To DataTable
Dim dr As DataRow
dr = dt.NewRow()
dr(0) = "Test"
dr(1) = "Test Test"
dr(2) = "Test Test Test"
dr(3) = "This is a test to see if i can get this code to wrap or not by setting the width of the link button to a width of 100px. Lets see if it works"
dt.Rows.Add(dr)

'Bind Data
With Me.dlTest
.DataSource = dt
.DataBind()
End With
End Sub

<asp:DataList ID="dlTest" runat="server" Width="100%">
<ItemTemplate>
<table width="100%" border="1">
<tr>
<td><asp:Linkbutton id="lnkColumn1" runat="server" text='<%# Eval("Column1") %>'/></td>
<td><asp:Linkbutton id="Linkbutton2" runat="server" text='<%# Eval("Column2") %>'/></td>
<td><asp:Linkbutton id="Linkbutton3" runat="server" text='<%# Eval("Column3") %>'/></td>
<td><asp:Linkbutton id="Linkbutton4" runat="server" width="100px" text='<%# Eval("Column4") %>'/></td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>