Hi smile,
Remove these property from GridView.
RowStyle-Wrap="false"
HeaderStyle-Wrap="false"
And also remove Wrap="false" from below line of code.
smile says:
<
HeaderStyle
HorizontalAlign
=
"Left"
Width
=
"100%"
Wrap
=
"false"
/>
You need to set same width size for gridview and div, refer below sample.
HTML
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<script type="text/javascript">
$(document).ready(function () {
var table = $("table[id*=GridView1]");
$("#container").html($(table)[0].outerHTML);
$("#container [id*=GridView1]").find("tr:not(:nth-child(1)):not(:nth-child(2))").remove();
});
</script>
<div>
<div id="container">
</div>
<asp:GridView ID="GridView1" runat="server" AllowPaging="false" ShowFooter="true"
AutoGenerateColumns="false" RowStyle-Wrap="false" HeaderStyle-Wrap="false" Class="table table-striped table-bordered table-hover"
Style="width: 500px; border-collapse: collapse;">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="checkAll" runat="server" onclick="checkAll(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" onclick="Check_Click(this)" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="150px" DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField ItemStyle-Width="150px" DataField="Name" HeaderText="Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="Country" HeaderText="Country" />
<asp:BoundField ItemStyle-Width="150px" DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField ItemStyle-Width="150px" DataField="Name" HeaderText="Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="Country" HeaderText="Country" />
<asp:BoundField ItemStyle-Width="150px" DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField ItemStyle-Width="150px" DataField="Name" HeaderText="Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="Country" HeaderText="Country" />
<asp:BoundField ItemStyle-Width="150px" DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField ItemStyle-Width="150px" DataField="Name" HeaderText="Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="Country" HeaderText="Country" />
<asp:BoundField ItemStyle-Width="150px" DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField ItemStyle-Width="150px" DataField="Name" HeaderText="Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="Country" HeaderText="Country" />
<asp:BoundField ItemStyle-Width="150px" DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField ItemStyle-Width="150px" DataField="Name" HeaderText="Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="Country" HeaderText="Country" />
<asp:BoundField ItemStyle-Width="150px" DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField ItemStyle-Width="150px" DataField="Name" HeaderText="Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="Country" HeaderText="Country" />
<asp:BoundField ItemStyle-Width="150px" DataField="CustomerId" HeaderText="CustomerId" />
<asp:BoundField ItemStyle-Width="150px" DataField="Name" HeaderText="Name" />
<asp:BoundField ItemStyle-Width="150px" DataField="Country" HeaderText="Country" />
</Columns>
</asp:GridView>
</div>
Namespaces
C#
using System.Data;
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("CustomerId", typeof(int)),
new DataColumn("Name", typeof(string)),
new DataColumn("Country",typeof(string)) });
dt.Rows.Add(1, "John Hammond", "United States");
dt.Rows.Add(2, "Mudassar Khan", "India");
dt.Rows.Add(3, "Suzanne Mathews", "France");
dt.Rows.Add(4, "Robert Schidner", "Russia");
GridView1.DataSource = dt;
GridView1.DataBind();
}
}