Datatables not working with master page asp.net
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/FormsV2/Site1.Master" CodeBehind="Listcharge.aspx.vb" Inherits="STMIS.Listcharge1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.12/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/buttons/1.2.2/css/buttons.dataTables.min.css" />
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.2.min.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<script type="text/javascript">
$(function () {
$('#gvCustomers tfoot tr').appendTo('#gvCustomers thead');
$('#gvCustomers').removeAttr('width').DataTable({
bLengthChange: true,
lengthMenu: [[5, 10, -1], [5, 10, "All"]],
bFilter: true,
bSort: true,
paging: true,
fixedColumns: false,
orderCellsTop: true
});
});
</script>
<body>
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table class="auto-style1">
<tr>
<td class="auto-style4">
Single</td>
<td class="auto-style4">
<asp:TextBox ID="Singlek" runat="server" Width="114px"></asp:TextBox>
</td>
<td class="auto-style8">
Double</td>
<td class="auto-style8">
<asp:TextBox ID="Doublesk" runat="server"></asp:TextBox>
</td>
<td class="auto-style8">
Route</td>
<td class="auto-style8">
<asp:TextBox ID="FRoute0" runat="server" Width="344px"></asp:TextBox>
</td>
<td class="auto-style8">
<asp:Label ID="EntryCodeK" runat="server"></asp:Label>
</td>
<td class="auto-style8">
<asp:Button ID="Button2" runat="server" Text="Update Data" />
</td>
<td class="auto-style6">
<asp:Button ID="Button4" runat="server" Text="Back To Menu" />
</td>
</tr>
<tr>
<td class="auto-style9" colspan="9">
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="False" ShowFooter="True" OnRowCommand="gvCustomers_RowCommand">
<Columns>
<asp:TemplateField HeaderText="Single">
<EditItemTemplate>
<asp:TextBox ID="txtsingle" runat="server" Text='<%# Bind("Single") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="Fsingle" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Singles" runat="server" Text='<%# Bind("Single") %>'></asp:Label>
<br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Double">
<EditItemTemplate>
<asp:TextBox ID="txtdouble" runat="server" Text='<%# Bind("Doubles") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="Fdouble" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Doubles" runat="server" Text='<%# Bind("Doubles") %>'></asp:Label>
<br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Route">
<EditItemTemplate>
<asp:TextBox ID="txtroute" runat="server" Text='<%# Bind("Route") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="FRoute" runat="server" Width="344px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Routes" runat="server" Text='<%# Bind("Route") %>'></asp:Label>
<br />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EntryCode">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("atk") %>' Height="16px" Width="59px"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Text="AddNew" />
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Entrycode" runat="server" Text='<%# Bind("atk") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField CommandName="Edit1" Text="Edit" HeaderText="Edit" />
<asp:TemplateField HeaderText="DelSingle">
<FooterTemplate>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="lnkRemove" runat="server" CommandArgument='<%# Bind("atk")%>' OnClick="DeleteCustomer" OnClientClick="return confirm('Do you want to delete?')" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
<tr>
<td colspan="8">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
</td>
<td class="auto-style2"> </td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</body>
</html>
<script type="text/javascript">
//On UpdatePanel Refresh
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm != null) {
prm.add_endRequest(function (sender, e) {
if (sender._postBackSettings.panelsToUpdate != null) {
$('[id$=gvCustomers]').prepend($("<thead></thead>").append($('[id$=gvCustomers]').find("tr:first"))).DataTable({
"responsive": true,
"sPaginationType": "full_numbers"
});
}
});
};
</script>
</asp:Content>
Imports System.Data
Imports System.Web.Services
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Threading
Public Class Listcharge1
Inherits System.Web.UI.Page
Dim conString As String = ConfigurationManager.ConnectionStrings("STMISWEBConnectionString").ConnectionString
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then Bindroute()
End Sub
Private Sub Bindroute()
Dim cmdt As New SqlCommand("SELECT * FROM ListCharge")
gvCustomers.DataSource = Me.ExecuteQuery(cmdt, "SELECT")
gvCustomers.DataBind()
'Required for jQuery DataTables to work.
gvCustomers.UseAccessibleHeader = True
gvCustomers.FooterRow.TableSection = TableRowSection.TableFooter
gvCustomers.HeaderRow.TableSection = TableRowSection.TableHeader
End Sub
Private Function ExecuteQuery(ByVal cmd As SqlCommand, ByVal action As String) As DataTable
'Dim conString As String = conString
Using con As New SqlConnection(conString)
cmd.Connection = con
Select Case action
Case "SELECT"
Using sda As New SqlDataAdapter()
sda.SelectCommand = cmd
Using dt As New DataTable()
sda.Fill(dt)
Return dt
End Using
End Using
Case "UPDATE"
con.Open()
cmd.ExecuteReader()
con.Close()
Exit Select
End Select
Return Nothing
End Using
End Function
Protected Sub gvCustomers_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gvCustomers.RowCommand
If e.CommandName = "Edit1" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim row As GridViewRow = gvCustomers.Rows(index)
Dim Singles As Label = CType(row.FindControl("Singles"), Label)
Dim Doubles As Label = CType(row.FindControl("Doubles"), Label)
Dim Entrycode As Label = CType(row.FindControl("Entrycode"), Label)
Dim Routes As Label = CType(row.FindControl("Routes"), Label)
Singlek.Text = Singles.Text
Doublesk.Text = Doubles.Text
EntryCodeK.Text = Entrycode.Text
FRoute0.Text = Routes.Text
If Not IsPostBack Then Bindroute()
' Exit Sub
End If
End Sub
Protected Sub Button3_Click(sender As Object, e As EventArgs)
Dim txtsingle As String = DirectCast(gvCustomers.FooterRow.FindControl("fsingle"), TextBox).Text
Dim txtdouble As String = DirectCast(gvCustomers.FooterRow.FindControl("fdouble"), TextBox).Text
Dim txtRoute As String = DirectCast(gvCustomers.FooterRow.FindControl("froute"), TextBox).Text
Dim txtAddParticulars As TextBox = CType(gvCustomers.FooterRow.FindControl("fsingle"), TextBox)
Dim txtAddParticulars2 As TextBox = CType(gvCustomers.FooterRow.FindControl("fdouble"), TextBox)
Dim txtAddParticulars3 As TextBox = CType(gvCustomers.FooterRow.FindControl("froute"), TextBox)
If String.IsNullOrEmpty(txtsingle) Then
ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('You Must indicate the Route Charges');", True)
txtAddParticulars.Focus()
Exit Sub
Else
If String.IsNullOrEmpty(txtdouble) Then
ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('You Must indicate the Route Charges');", True)
txtAddParticulars2.Focus()
Exit Sub
Else
If String.IsNullOrEmpty(txtRoute) Then
ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('You Must indicate the Route Name');", True)
txtAddParticulars3.Focus()
Exit Sub
End If
End If
End If
Dim sqlConnection12 As New SqlConnection(conString)
Dim objCommand22 As SqlCommand = New SqlCommand()
Dim cmd2 As New SqlCommand
cmd2.CommandText = "Pushcharges"
cmd2.CommandType = CommandType.StoredProcedure
cmd2.Connection = sqlConnection12
cmd2.Parameters.Add("@sj", SqlDbType.NVarChar, 150).Value = txtsingle
cmd2.Parameters.Add("@cal", SqlDbType.NVarChar, 50).Value = txtdouble
cmd2.Parameters.Add("@r", SqlDbType.NVarChar, 350).Value = txtRoute
sqlConnection12.Open()
cmd2.ExecuteReader()
sqlConnection12.Close()
ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('Route Added Successfully');", True)
txtAddParticulars.Text = ""
txtAddParticulars2.Text = ""
txtAddParticulars3.Text = ""
If Not IsPostBack Then Bindroute()
Exit Sub
End Sub
Protected Sub DeleteCustomer(ByVal sender As Object, ByVal e As EventArgs)
Dim lnkRemove As LinkButton = DirectCast(sender, LinkButton)
Using Con As New SqlConnection(conString)
Con.Open()
Using cmd As New SqlCommand
cmd.Connection = Con
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "Delsingleitem"
cmd.Parameters.Add("@t", SqlDbType.NVarChar).Value = lnkRemove.CommandArgument
cmd.ExecuteReader()
Con.Close()
End Using
End Using
'BindItemList()
If Not IsPostBack Then Bindroute()
Response.Redirect(Request.Url.AbsoluteUri)
Exit Sub
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If String.IsNullOrEmpty(Singlek.Text) Then
ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('You Must indicate the Single Route Charges by Selecting from the List');", True)
Singlek.Focus()
Exit Sub
Else
If String.IsNullOrEmpty(Doublesk.Text) Then
ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('You Must indicate the Double Route Charges by Selecting from the List');", True)
Doublesk.Focus()
Exit Sub
Else
If String.IsNullOrEmpty(FRoute0.Text) Then
ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('You Must indicate the Route Name by Selecting from the List');", True)
FRoute0.Focus()
Exit Sub
End If
End If
End If
Dim sqlConnection12 As New SqlConnection(conString)
Dim objCommand22 As SqlCommand = New SqlCommand()
Dim cmd2 As New SqlCommand
cmd2.CommandText = "chargesEdit"
cmd2.CommandType = CommandType.StoredProcedure
cmd2.Connection = sqlConnection12
cmd2.Parameters.Add("@sj", SqlDbType.NVarChar, 150).Value = Singlek.Text
cmd2.Parameters.Add("@cal", SqlDbType.NVarChar, 50).Value = Doublesk.Text
cmd2.Parameters.Add("@r", SqlDbType.NVarChar, 350).Value = FRoute0.Text
cmd2.Parameters.Add("@k", SqlDbType.Int).Value = EntryCodeK.Text
sqlConnection12.Open()
cmd2.ExecuteReader()
sqlConnection12.Close()
Singlek.Text = ""
Doublesk.Text = ""
FRoute0.Text = ""
EntryCodeK.Text = ""
If Not IsPostBack Then Bindroute()
' Response.Redirect(Request.Url.AbsoluteUri)
' ScriptManager.RegisterStartupScript(Me, [GetType](), "showalert", "alert('Route Updated Successfully');", True)
ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "showalert", "alert('Record Updated Successfully');window.location ='" + Request.Url.AbsoluteUri + "';", True)
Exit Sub
End Sub
Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Response.Redirect(String.Format("~/FormsV2/Dashboardloader.aspx"))
End Sub
End Class