I noticed that the Wrap only breaks on spaces. Is there a way to break the data when there is no spaces? This column displays urls and can cause the column to extend too far and distorts the grid and other columns. Especially when some urls have no spaces.
Thanks
This is my code retrieving and binding the data:
Private Sub PopulateGrid(ByVal bind As Boolean)
'Dim rpt As Reports
Dim aReports As ArrayList = New ArrayList
Dim sSQL As String = ""Dim sSQLWhere As String = ""Dim sCategory As String = ""Dim sCat As String = ""Dim DB As New ADODB.Connection
Dim RS As ADODB.Recordset
DB.Open("DSN=Test", "aa", "123")
Try
sSQL = "SELECT * FROM dep_reports"If txtSearchName.Text <> ""And ddlSearchCategory.Text <> ""Then
lblStatus.Text = "You must use one of the fields for your search"GoTo StopGrid
ElseIf txtSearchName.Text <> ""And ddlSearchCategory.Text = ""Then
sSQLWhere = " WHERE rep_name = '" & txtSearchName.Text.Trim.ToUpper & "'"
ElseIf txtSearchName.Text = "" And ddlSearchCategory.Text <> "" Then
sCategory = ddlSearchCategory.Text.Trim.ToUpper
sCat = GetCategory(sCategory)
sSQLWhere = " WHERE rep_cat = '" & sCat & "'"
Else
sSQLWhere = ""End If
sSQL += sSQLWhere
sSQL += " ORDER BY rep_name"
RS = DB.Execute(sSQL)
While Not RS.EOF
rpt = New Reports
rpt.Name = RS.Fields("rep_name").Value.ToString.Trim
rpt.Desc = RS.Fields("rep_desc").Value.ToString.Trim
rpt.Role = RS.Fields("rep_role").Value.ToString.Trim
rpt.Category = RS.Fields("rep_cat").Value.ToString.Trim
rpt.URL = RS.Fields("rep_url").Value.ToString.Trim
rpt.Keywords = RS.Fields("rep_keywords").Value.ToString.Trim
rpt.LastUsed = RS.Fields("rep_last_used").Value.ToString.Trim
rpt.LongDesc = RS.Fields("rep_long_desc").Value.ToString.Trim
aReports.Add(rpt)
RS.MoveNext()
End While
Session("Reports") = aReports
If bind Then
BindData()
End If
Catch ex As Exception
lblStatus.Text = "Error retrieving Report information." & ex.Message & " " & sSQL
End Try
DB.Close()
StopGrid:
End Sub
Private Sub BindData()
gvReport.DataSource = Session("Reports")
gvReport.DataBind()
gvReport.SelectedIndex = -1
End Sub
It works nicely, but is there a way to just set that to the url column in the grid and not all the columns? I would like the other columns to still break on the spaces since I don't have a long string issue with any of them.
Another way that I could think of is to limit the data to be displayed in the GridView instead and display
the Full content of the data in the ToolTip.. see below
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { ViewState["OrigData"] = e.Row.Cells[0].Text; if (e.Row.Cells[0].Text.Length >= 30) //Just change the value of 30 based on your requirements { e.Row.Cells[0].Text = e.Row.Cells[0].Text.Substring(0, 30) + "..."; e.Row.Cells[0].ToolTip = ViewState["OrigData"].ToString(); }
lkrterp
0 Points
25 Posts
gridview wrapping column with no space in data
Apr 30, 2009 04:16 PM|LINK
Hi All!
I have a question concerning the wrapping of data in a gridview column. I set my bound field item style as follows for a particular column.
<asp:BoundField DataField="url" HeaderText="URL" ItemStyle-Width="15%" SortExpression="url"> <ItemStyle Font-Size="8pt" Wrap="true" Width="20%"></asp:BoundField>I noticed that the Wrap only breaks on spaces. Is there a way to break the data when there is no spaces? This column displays urls and can cause the column to extend too far and distorts the grid and other columns. Especially when some urls have no spaces.
Thanks
This is my code retrieving and binding the data:
vinz
All-Star
116098 Points
16314 Posts
MVP
Re: gridview wrapping column with no space in data
Apr 30, 2009 05:37 PM|LINK
You can set style to GridView like below
See the following threads below for more detail:
http://forums.asp.net/p/1396420/3003621.aspx
http://forums.asp.net/t/1307972.aspxMessageBox Controls for WebForms |Blog
lkrterp
0 Points
25 Posts
Re: gridview wrapping column with no space in data
Apr 30, 2009 06:58 PM|LINK
Thanks for the response vinz!
It works nicely, but is there a way to just set that to the url column in the grid and not all the columns? I would like the other columns to still break on the spaces since I don't have a long string issue with any of them.
vinz
All-Star
116098 Points
16314 Posts
MVP
Re: gridview wrapping column with no space in data
Apr 30, 2009 07:13 PM|LINK
have tried adding the attributes for that column only?
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[0].Attributes.Add("style", "word-break:break-all;word-wrap:break-word"); } } protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { this.GridView1.Columns[0].ItemStyle.Width = new Unit(100); }Another way that I could think of is to limit the data to be displayed in the GridView instead and display the Full content of the data in the ToolTip.. see below
MessageBox Controls for WebForms |Blog
lkrterp
0 Points
25 Posts
Re: gridview wrapping column with no space in data
Apr 30, 2009 07:41 PM|LINK
Thanks again Vinz!
I had to convert to vb; and your first suggestion is working perfectly in my code.
One question... what is the purpose of the new Unit[100]. It works, but just curious.
Now I would like to have one of those beers to go with my music and code! [:)]
vinz
All-Star
116098 Points
16314 Posts
MVP
Re: gridview wrapping column with no space in data
Apr 30, 2009 08:03 PM|LINK
Glad to hear that it works or you! :)
The Unit structure represents a length measurement that can be expressed in any HTML-compatible size unit. For more info then see: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.unit.aspx
[:D] Cheers for that!
BTW,If you're issue was resolved, then don't forget to mark those helpful post(s) as anwser(s) for future references...
MessageBox Controls for WebForms |Blog