how to make gridview column text no wrap and how to create a resizable column header
-
Hi, all, I have create a gridview in asp.net with C#, there is a column called Project Name which sometimes has long text, now if it's longer then column width, it will wrap to two line, I don't like this, I want to hide the longer part, how can I do it?? The second question is how can I make gridview header column resizable? is it possible if don't use AJAX? Thanks! Andraw
-
Hi, all, I have create a gridview in asp.net with C#, there is a column called Project Name which sometimes has long text, now if it's longer then column width, it will wrap to two line, I don't like this, I want to hide the longer part, how can I do it?? The second question is how can I make gridview header column resizable? is it possible if don't use AJAX? Thanks! Andraw
Hi Andraw, you can use the DataBound event of the Gridview as per the below code:
protected void gvProjects_RowDataBound(object sender, GridViewRowEventArgs e)
{
string projectName = ((DataRowView)e.Row.DataItem)["ProjectName"].ToString();
if (projectName.Length > 200)
{
projectName.Substring(0, 200);
}
}or you can loop over the list/DataTable (the Datasource) that you are using to bind your GridView and check the length of the project name and Substring it.
Regards, Jamil
-
Hi, all, I have create a gridview in asp.net with C#, there is a column called Project Name which sometimes has long text, now if it's longer then column width, it will wrap to two line, I don't like this, I want to hide the longer part, how can I do it?? The second question is how can I make gridview header column resizable? is it possible if don't use AJAX? Thanks! Andraw
as for resizing the column please check the following article: http://www.dotnetspider.com/resources/18257-Gridview-Resizable-column.aspx
Regards, Jamil
-
Hi Andraw, you can use the DataBound event of the Gridview as per the below code:
protected void gvProjects_RowDataBound(object sender, GridViewRowEventArgs e)
{
string projectName = ((DataRowView)e.Row.DataItem)["ProjectName"].ToString();
if (projectName.Length > 200)
{
projectName.Substring(0, 200);
}
}or you can loop over the list/DataTable (the Datasource) that you are using to bind your GridView and check the length of the project name and Substring it.
Regards, Jamil
-
Hi, Jamil, Thanks for your reply. If I limited the text length, when I resize the column width, the cut part cannot be displayed, right? why doesn't work? I will try your link in the next reply.
yes , if you set the length of the text then when resizing the column the hidden part of the text will appear again because it is already rendered. This is totally related to the pattern of resizing that you are going to use.
Regards, Jamil
-
as for resizing the column please check the following article: http://www.dotnetspider.com/resources/18257-Gridview-Resizable-column.aspx
Regards, Jamil
Hi, Jamil, I try the codes in your link, but it doesn't work for me, I don't know why. I have my gridview decalred as the following: also my page is web content page, I put the gridview in
tag to create scroll bar and fixed the header while scroll, do these features affect the resizing? Thanks!
-
yes , if you set the length of the text then when resizing the column the hidden part of the text will appear again because it is already rendered. This is totally related to the pattern of resizing that you are going to use.
Regards, Jamil
-
But if we fixed the text length to 200, even the column is resized, we still cannot see the extra part, am I right?
yes you are right.