TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
taha suliman
1.4k
368
6.5k
Get Selected row for Bootsrap Datatable in GridView not work
Feb 6 2020 4:08 AM
<
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 Rows
</
button
>
<
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 <thead> instead of <tbody> - 11/03/2013 - MCR.
gv.HeaderRow.TableSection = TableRowSection.TableHeader;
}
if
(gv.ShowFooter ==
true
&& gv.Rows.Count > 0)
{
//Force GridView to use <tfoot> instead of <tbody> - 11/03/2013 - MCR.
gv.FooterRow.TableSection = TableRowSection.TableFooter;
}
}
//----------------
}
releated to the Bootstrap DataTable in the bellow link
https://jsfiddle.net/mmushtaq/q67L1a9a/
Reply
Answers (
1
)
how to build new framework?
SMTP Server requires a secure connection or client