本文介绍了我们可以在网格视图中使用read more选项显示部分数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据网格显示项目详细信息,如代码,单价,品牌,描述等等

i想要一个描述列,阅读更多超链接选项

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

推荐答案

<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

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.


这篇关于我们可以在网格视图中使用read more选项显示部分数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 09:43