Hi rakeshkuma,
You need to re-apply the DataTable plugin after partial postback (Update Panel refresh).
HTML
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<link href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script type='text/javascript'>
$(function () {
$("[id*=gvCompany]").DataTable({
bLengthChange: true,
lengthMenu: [[5, 10, 25, -1], [5, 10, 25, "All"]],
bFilter: true,
bSort: false,
bPaginate: true
});
});
//On UpdatePanel Refresh.
var prm = Sys.WebForms.PageRequestManager.getInstance();
if (prm != null) {
prm.add_endRequest(function (sender, e) {
if (sender._postBackSettings.panelsToUpdate != null) {
$("[id*=gvCompany]").DataTable({
bLengthChange: true,
lengthMenu: [[5, 10, 25, -1], [5, 10, 25, "All"]],
bFilter: true,
bSort: false,
bPaginate: true
});
}
});
};
</script>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" runat="server">
<ContentTemplate>
<asp:GridView ID="gvCompany" runat="server" ClientIDMode="Static" AutoGenerateColumns="false" Width="100%" CssClass="table table-bordered table-striped" DataKeyNames="field1">
<Columns>
<asp:TemplateField HeaderText="#" HeaderStyle-Width="20px" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label runat="server" ID="lblpono" Text=' <%# Container.DataItemIndex + 1 %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" AutoPostBack="true" Style="border: 1px solid #fff;" OnCheckedChanged="OnCheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox runat="server" AutoPostBack="true" ID="chkDel" OnCheckedChanged="OnCheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="field2" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Font-Bold="true">
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("field2") %>'></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("field2") %>' CssClass="form-control" Visible="false" Width="100%"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="field3" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Font-Bold="true">
<ItemTemplate>
<asp:Label ID="lblCountry" runat="server" Text='<%# Eval("field3") %>'></asp:Label>
<asp:DropDownList ID="ddlCountries" runat="server" CssClass="form-control" Visible="false" Width="100%">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<hr />
<asp:Button ID="btnUpdate" runat="server" Text="UPDATE" CssClass="btn btn-primary btn-xs" Visible="false" />
<asp:Button ID="btnDelete" runat="server" Text="DELETE" CssClass="btn btn-primary btn-xs" Visible="false" />
</ContentTemplate>
<Triggers>
</Triggers>
</asp:UpdatePanel>
Code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
BindGridView()
End If
End Sub
Private Sub BindGridView()
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(2) {
New DataColumn("field1"),
New DataColumn("field2"),
New DataColumn("field3")})
dt.Rows.Add(1, "John Hammond", "United States")
dt.Rows.Add(2, "Mudassar Khan", "India")
dt.Rows.Add(3, "Suzanne Mathews", "France")
dt.Rows.Add(4, "Robert Schidner", "Russia")
gvCompany.DataSource = dt
gvCompany.DataBind()
gvCompany.UseAccessibleHeader = True
gvCompany.HeaderRow.TableSection = TableRowSection.TableHeader
End Sub
Protected Sub OnCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim isUpdateVisible As Boolean = False
Dim chk As CheckBox = (TryCast(sender, CheckBox))
If chk.ID = "chkAll" Then
For Each row As GridViewRow In gvCompany.Rows
If row.RowType = DataControlRowType.DataRow Then
row.Cells(1).Controls.OfType(Of CheckBox)().FirstOrDefault().Checked = chk.Checked
End If
Next
End If
Dim chkAll As CheckBox = (TryCast(gvCompany.HeaderRow.FindControl("chkAll"), CheckBox))
chkAll.Checked = True
For Each row As GridViewRow In gvCompany.Rows
If row.RowType = DataControlRowType.DataRow Then
Dim isChecked As Boolean = row.Cells(1).Controls.OfType(Of CheckBox)().FirstOrDefault().Checked
For i As Integer = 2 To row.Cells.Count - 1
row.Cells(i).Controls.OfType(Of Label)().FirstOrDefault().Visible = Not isChecked
If row.Cells(i).Controls.OfType(Of TextBox)().ToList().Count > 0 Then
row.Cells(i).Controls.OfType(Of TextBox)().FirstOrDefault().Visible = isChecked
End If
If row.Cells(i).Controls.OfType(Of DropDownList)().ToList().Count > 0 Then
row.Cells(i).Controls.OfType(Of DropDownList)().FirstOrDefault().Visible = isChecked
End If
If isChecked AndAlso Not isUpdateVisible Then
isUpdateVisible = True
End If
If Not isChecked Then
chkAll.Checked = False
End If
Next
End If
Next
gvCompany.UseAccessibleHeader = True
gvCompany.HeaderRow.TableSection = TableRowSection.TableHeader
btnUpdate.Visible = isUpdateVisible
btnDelete.Visible = isUpdateVisible
End Sub
Screenshot