Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have a datagrid showing item details like code, unit price,brand ,description and many more
i want a column for description with Read More hyperlink option
Posted
Comments
Rockstar_ 20-May-13 7:43am    
add one more itemtemplate then add a hyperlink

1 solution

In source page add gridview and follow the bellow code(modify code lil bit by your self).

C#
<asp:templatefield headertext="Description" xmlns:asp="#unknown">
 <itemtemplate>
      <asp:label id="lblDescription" runat="server">
                Text='<%# Limit(Eval("Description"),40) %>' 
                Tooltip='<%# Eval("Description") %>'>
      </asp:label>
      <asp:linkbutton id="ReadMoreLinkButton" runat="server">
                Text="Read More"
                Visible='<%# SetVisibility(Eval("Description"), 40) %>'
                OnClick="ReadMoreLinkButton_Click">
      
 </asp:Label>
 </ItemTemplate>
</asp:TemplateField>



And code-behind

C#
protected bool SetVisibility(object Desc, int length)
{
    return Desc.ToString().Length > length;
}
protected void ReadMoreLinkButton_Click(object sender, EventArgs e)
{
    LinkButton button = (LinkButton)sender;
    GridViewRow row = button.NamingContainer as GridViewRow;
    Label descLabel = row.FindControl("lblDescription") as Label;
    button.Text = (button.Text == "Read More") ? "Hide" : "Read More";
    string temp = descLabel.Text;
    descLabel.Text = descLabel.ToolTip;
    descLabel.ToolTip = temp;
}


Hope it helps.
 
Share this answer
 
v3
Comments
govindi unal 20-May-13 12:44pm    
giving error 'limit' is not declared. It may be inaccessible due to its protection level.
declare function for limit
Public Shared Function Limit(ByVal Desc As Object, ByVal length As Integer) As String
Dim strDesc As New StringBuilder()
strDesc.Insert(0, Desc.ToString())

If strDesc.Length > length Then
Return strDesc.ToString().Substring(0, length) + "..."
Else
Return strDesc.ToString()
End If
End Function
pupose solved
thank you
Member 12075043 13-Feb-16 2:14am    
Hi.. Can you provide in c# same? Please.. Thanks in advance

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900