- <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 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions01ForumsTop experts
Arun PottiAnswers in the forums20answers02
Tahir AnsariAnswers in the forums5answers03
Kamlesh KumarAnswers in the forums5answers04
Sam HobbsAnswers in the forums4answers05
Željko PerićAnswers in the forums3answersFull leaderboard →
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Loading
Siddharth GajbhiyeRank #376 · 6.7K reputationPosted Feb 8, 2020, 9:35 PM EST