如何在网格视图中使用“读取更多”按钮来限制文本和显示全文 [英] How to limit the text and display full text with read more button in grid view
本文介绍了如何在网格视图中使用“读取更多”按钮来限制文本和显示全文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
How to limit the text and display full text with Read More button in grid view
我尝试过:
What I have tried:
DataTable table=new DataTable();
//GridView1.DataSource = table;
string str2 = "select id,title,description from tbl_event order by id desc";
obj.ds = obj.ret_ds(str2);
GridView1.DataSource = obj.ds;
GridView1.DataBind();
int i = 0;
foreach (DataRow row in table.Rows)
{
string x = row["description"].ToString();
if (x.Length > 10)
{
GridView1.Rows[i].Cells[0].Text = x.Substring(0, 10) + "<a href=EventDetail.aspx>Read More </a>";
}
i++;
if (i >= table.Rows.Count)
{
return;
}
}
但这段代码不起作用。
But this code is not working.
推荐答案
好吧,你必须添加TemplateFiled(gridview的另一列)。有关详细信息,请参阅:
如何:响应GridView控件中的按钮事件 [ ^ ]
< a href =https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.columns(v=vs.110).aspx> GridView.Columns属性(System.Web .UI.WebControls) [ ^ ]
Well, you have to add TemplateFiled (another column of gridview). For farther details, please, see:
How to: Respond to Button Events in a GridView Control[^]
GridView.Columns Property (System.Web.UI.WebControls)[^]
这篇关于如何在网格视图中使用“读取更多”按钮来限制文本和显示全文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文