i have a datagrid which contains a lot of information in one column. I would like a way for the user to preview some of the content in 开发者_如何学Pythonthat column and then click a "more" hyperlink in that column that takes them to another page that displays all the information in that column allowing them to add more info into it and other items in that row.
I have done the more hyper link on the end of all the information but i would i change for example:
"HI my name is stefan i like walking on the beach and other stuff...more"
to
"Hi my name is stefan... more"
And how would i pull up the selected row in an new datagrid on a new asp page after they click more?
When i click the more hyperlink it doesn't open the correct row but only blogid 2.
you can use HyperLink in GridView. You can use CommangArgument and CommandName Property to Hold the specic data. When u clicked the hyperlink the data will be passed as querystring to the next page. so that you can use the querytring
And to display " ... more" you can use substring method.. substring for a legnth and concat the ....more to your hyperlink text.
MSDN for CommandArgument
Sample for Passing data with LinkButton
Handle OnRowDataBound as so:
protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
// say for example that the column with long text is the 5th one
e.Row.Cells[5].Text = e.Row.Cells[5].Text.Length>20?e.Row.Cells[5].Substring(0,20)+" <a href=\"DetailsPage.aspx?BlogID=\""+e.Row.Cells[0].Text+"\"> more...</a>";
}
}
Where the first column (Cells[0]
) has the blog ID. I think that's how you have your gridview now.
I think maybe you're looking for the text-overflow: ellipsis;
CSS styling. You can then use jQuery or plain javascript to toggle the style and reveal all the text.
I'm not quite sure how this is handled by Firefox today, but IE is ok.
I managed to fix this by using an sql query, Left(content,50)
Which displays the first 50 characters.
You can try following code:
<asp:TemplateField HeaderText="Description" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<%# (Eval("strDescription").ToString().Length > 55 ? Eval("strDescription").ToString().Substring(0, 55) + "....." : Eval("strDescription"))%>
</ItemTemplate>
</asp:TemplateField>
and just add hyperlink in this item template and assign your blogid(in your case) to that hyperlink to open detail page that you want.
精彩评论