- <html xmlns="http://www.w3.org/1999/xhtml">
- <head runat="server">
- <title>title>
- <link href="files/jquery.dataTables.min.css" rel="stylesheet" />
- <link href="files/select.dataTables.min.css" rel="stylesheet" />
- head>
- <body>
- <form id="form1" runat="server">
- <div style="padding:50px;">
- <button id="btnSelectedRows" type="button">Get Selected Rowsbutton>
- <hr />
- <asp:GridView ID="GridView1" OnPreRender="GridView_PreRender" ShowFooter="true"
- AutoGenerateColumns="False" CssClass="table table-striped table-bordered" runat="server">
- <Columns>
- <asp:BoundField DataField="" HeaderText="" />
- <asp:BoundField DataField="Id" HeaderText="Id" />
- <asp:BoundField DataField="Name" HeaderText="Name" />
- <asp:BoundField DataField="Position" HeaderText="Position"/>
- <asp:BoundField DataField="Office" HeaderText="Office" />
- <asp:BoundField DataField="Extn" HeaderText="Extn"/>
- <asp:BoundField DataField="Start date" DataFormatString="{0:dd-MM-yyyy}" HeaderText="Start date"/>
- <asp:BoundField DataField="Salary" HeaderText="Salary"/>
- Columns>
- asp:GridView>
- div>
- form>
- <script src="files/jquery-1.12.4.js">script>
- <script src="files/jquery.dataTables.min.js">script>
- <script src="files/dataTables.select.min.js">script>
- <script>
- $(document).ready(function () {
- table = $('#<%= GridView1.ClientID %>').dataTable({
- columnDefs: [{
- orderable: false,
- className: 'select-checkbox',
- targets: 0
- }, {
- "targets": [2],
- "visible": false,
- "searchable": false
- }],
- select: {
- style: 'os',
- selector: 'td:first-child'
- },
- "aLengthMenu": [[10, 50, 75, -1], [10, 50, 75, "All"]],
- "iDisplayLength": 10,
- "order": [[2, "asc"]],
- stateSave: true,
- stateSaveCallback: function (settings, data) {
- localStorage.setItem('DataTables_' + settings.sInstance, JSON.stringify(data));
- },
- stateLoadCallback: function (settings) {
- return JSON.parse(localStorage.getItem('DataTables_' + settings.sInstance));
- }
- });
- });
- $('#btnSelectedRows').on('click', function () {
- var tblData = table.rows('.selected').data();
- var tmpData;
- $.each(tblData, function (i, val) {
- tmpData = tblData[i];
- alert(tmpData);
- });
- });
- script>
- body>
- html>
- ---------------------------------------
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class Default2 : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- getdata();
- }
- }
- private void getdata()
- {
- string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
- SqlConnection con = new SqlConnection(constr);
- var commandStr = "select * from EmployeeData ";
- using (SqlCommand command = new SqlCommand(commandStr, con))
- {
- using (SqlDataAdapter sda = new SqlDataAdapter(command))
- {
- DataTable dt = new DataTable();
- sda.Fill(dt);
- GridView1.DataSource = dt;
- GridView1.DataBind();
- }
- }
- }
- protected void GridView_PreRender(object sender, EventArgs e)
- {
- GridView gv = (GridView)sender;
- if ((gv.ShowHeader == true && gv.Rows.Count > 0)
- || (gv.ShowHeaderWhenEmpty == true))
- {
- //Force GridView to use instead of - 11/03/2013 - MCR.
- gv.HeaderRow.TableSection = TableRowSection.TableHeader;
- }
- if (gv.ShowFooter == true && gv.Rows.Count > 0)
- {
- //Force GridView to use instead of - 11/03/2013 - MCR.
- gv.FooterRow.TableSection = TableRowSection.TableFooter;
- }
- }
- //----------------
- }
releated to the Bootstrap DataTable in the bellow link
https://jsfiddle.net/mmushtaq/q67L1a9a/1 Reply
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Loading
Siddharth GajbhiyePosted Feb 9, 2020, 2:35 AM