我尝试使用此示例进行搜索和排序,但在此示例中,他们使用表格,我正在使用gridview
我试试这个
public DataTable info(string id)
{
try
{
Entities2 wr = new Entities2();
List<spvechile_Result> sv = wr.spvechile(id).ToList();
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(int));
foreach (var c in sv)
{
dt.Rows.Add(c.Name);
}
GridView1.DataSource = dt;
GridView1.DataBind();
return dt;
}
catch (Exception ex)
{
throw new Exception();
}
}
那么如何将这个例子用于gridview
最新更新
我修改了这个文件。
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
并删除padding-right:30px 所以在此之后这就是结果 这是更新的html
<div class="panel" id="paneldiv">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<div id="firstgrid">
<asp:GridView ID="GridView1" runat="server"
CssClass="table table-striped table-bordered" Width="100%" CellPadding="0"
Font-Names="Verdana" BackColor ="White" BorderColor="#CCCCCC" BorderStyle="None"
BorderWidth="1px" Font-Size="9pt">
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>
在最后一栏中有长文本,因为这种格式不正确,网格视图高度变得如此长,如何管理
答案 0 :(得分:1)
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/dataTables.bootstrap.min.css" />
<script type="text/javascript" src="//code.jquery.com/jquery-1.12.3.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script>
<script>
$(document).ready(function () {
$("#GridView1").prepend($("<thead></thead>").append($(this).find("tr:first"))).dataTable({
"aoColumnDefs": [{ 'bSortable': false, 'aTargets': [3] }]
});
});
</script>
在gridview CssClass="table table-striped table-bordered"
中添加css类并设置Width="100%" CellPadding="0"
您的参考:jquery bootstrap datatable
<强>更新强>
<asp:GridView ID="GridView1" runat="server"
CssClass="table table-striped table-bordered" Width="100%" CellPadding="0"
Font-Names="Verdana" BackColor ="White" BorderColor="#CCCCCC" BorderStyle="None"
BorderWidth="1px" Font-Size="9pt">
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
我在您当前的CssClass="table table-striped table-bordered" Width="100%" CellPadding="0"
HTML
gridview