Hi micah,
Check this example. Now please take its reference and correct your code.
When you click in the Details link you will be redirect to the Details page with QueryString parameter as Id and based on that QueryString value get the Content from Database.
HTML
<asp:DataList ID="Getpost" runat="server" OnItemDataBound="OnItemDataBound" BorderStyle="Solid" BorderWidth="1">
<ItemTemplate>
<asp:Label ID="Label96" Text='<%#Eval("content")%>' runat="server" CssClass="" />
<asp:HyperLink ID="lnkRedirect" NavigateUrl='<%# string.Format("~/Details.aspx?Id={0}",Eval("Id")) %>'
runat="server" Text="Details..." />
<hr />
</ItemTemplate>
</asp:DataList>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[2] {
new System.Data.DataColumn("Id"), new System.Data.DataColumn("Content") });
dt.Rows.Add(1, "How do i make a long text in datalist show detail link");
dt.Rows.Add(2, "I want to make a text that is more than 200 characters display Detail link which when clicked redirects to another page can you give example is it like code behind or jquery based on the text length show hide the controls and on hyperlink click redirect to destination page");
dt.Rows.Add(3, "Test");
Getpost.DataSource = dt;
Getpost.DataBind();
}
}
protected void OnItemDataBound(object sender, DataListItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
if ((e.Item.FindControl("Label96") as Label).Text.Length > 200)
{
(e.Item.FindControl("Label96") as Label).Visible = false;
(e.Item.FindControl("lnkRedirect") as HyperLink).Visible = true;
}
else
{
(e.Item.FindControl("Label96") as Label).Visible = true;
(e.Item.FindControl("lnkRedirect") as HyperLink).Visible = false;
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim dt As System.Data.DataTable = New System.Data.DataTable()
dt.Columns.AddRange(New System.Data.DataColumn(1) {New System.Data.DataColumn("Id"), New System.Data.DataColumn("Content")})
dt.Rows.Add(1, "How do i make a long text in datalist show detail link")
dt.Rows.Add(2, "I want to make a text that is more than 200 characters display Detail link which when clicked redirects to another page can you give example is it like code behind or jquery based on the text length show hide the controls and on hyperlink click redirect to destination page")
dt.Rows.Add(3, "Test")
Getpost.DataSource = dt
Getpost.DataBind()
End If
End Sub
Protected Sub OnItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
If (TryCast(e.Item.FindControl("Label96"), Label)).Text.Length > 200 Then
TryCast(e.Item.FindControl("Label96"), Label).Visible = False
TryCast(e.Item.FindControl("lnkRedirect"), HyperLink).Visible = True
Else
TryCast(e.Item.FindControl("Label96"), Label).Visible = True
TryCast(e.Item.FindControl("lnkRedirect"), HyperLink).Visible = False
End If
End If
End Sub
Screenshot