[英]asp.net c# Display few characters in gridview hyperlink
Sorry in advance for the bad title! 不好意思,对不起!
I have a gridview
where i use sqldatasource
我在使用
sqldatasource
的gridview
中
The gridview
has a field called cover letter and it is a link button The title of the link button is view cover letter gridview
有一个称为求职信的字段,它是一个链接按钮。链接按钮的标题是视图求职信
<ItemTemplate>
<asp:LinkButton ID="cat" runat="server" CommandName="cat" CommandArgument='<%# Bind("Id") %>' >View Cover Letter</asp:LinkButton>
</ItemTemplate>
when i click on the view cover letter link a new window popup displaying the content of the cover letter 当我单击查看求职信链接时,会弹出一个新窗口,显示求职信的内容
Now what i want to do is change the text of the link button from View Cover Letter so it display like the first 10 or 20 characters of the cover letter and when i click on the link it will show the full content of the cover letter in the new window. 现在我要做的是从“查看求职信”中更改链接按钮的文本,使其显示为求职信的前10个或20个字符,当我单击链接时,它将显示求职信中的全部内容新窗口。
so it will be something like this: 所以会是这样的:
How can I do such a thing? 我该怎么做?
You can Use this: But make sure that you have some content in your cover letter content.. that was the reason you get the error. 您可以使用此方法:但请确保求职信内容中包含某些内容。这就是收到错误的原因。
<asp:TemplateField HeaderText="Cover Letter">
<ItemTemplate>
<a href='../Pages/CoverLetter.aspx?ID=<%# Eval("cover_id")%>' target="_blank" style="color: blue; text-decoration: underline"><%# Eval("cover_content").ToString().Length>10 ? Eval("cover_content").ToString().Substring(0,10):Eval("cover_content")%></a>
</ItemTemplate>
</asp:TemplateField>
所以你的代码会像
<ItemTemplate> <asp:LinkButton ID="cat" runat="server" CommandName="cat" CommandArgument='<%# Bind("Id") %>' Text='<%#Eval("coverLetter").ToString().Substring(0,20)%>'>View Cover Letter</asp:LinkButton> </ItemTemplate>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.