Hi kevinf,
You need to set the GridView cell css properties
display to block
overflow to scroll
white-space to nowrap
Refer below exapmple.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<style type="text/css">
.CellWrapper { display: block; overflow: scroll; white-space: nowrap; }
</style>
<asp:GridView ID="gvEmployees" runat="server" AutoGenerateColumns="false"
OnRowDataBound="OnRowDataBound">
<Columns>
<asp:BoundField DataField="EmployeeId" HeaderText="Id" />
<asp:BoundField DataField="FirstName" HeaderText="Name" />
<asp:BoundField DataField="Notes" HeaderText="Note" />
</Columns>
</asp:GridView>
Namespaces
C#
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
VB.Net
Imports System.Configuration
Imports System.Data
Imports System.Data.SqlClient
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGridView();
}
}
private void BindGridView()
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
string query = "SELECT TOP 2 * FROM Employees";
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand(query, con))
{
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
gvEmployees.DataSource = dt;
gvEmployees.DataBind();
}
}
}
}
}
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[2].Width = 300;
e.Row.Cells[2].ControlStyle.CssClass = "CellWrapper";
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Me.BindGridView()
End If
End Sub
Private Sub BindGridView()
Dim conString As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Dim query As String = "SELECT TOP 2 * FROM Employees"
Using con As SqlConnection = New SqlConnection(conString)
Using cmd As SqlCommand = New SqlCommand(query, con)
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Using dt As DataTable = New DataTable()
sda.Fill(dt)
gvEmployees.DataSource = dt
gvEmployees.DataBind()
End Using
End Using
End Using
End Using
End Sub
Protected Sub OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(2).Width = 300
e.Row.Cells(2).ControlStyle.CssClass = "CellWrapper"
End If
End Sub
Screenshot