AsyncFileUpload with GridView handle checkbox uncheck dynamically in asp.net
As per below image, I am trying to upload file on particular row so once it is upload complete for that row checkbox should set as unchecked and call postback call and reaming row should reaming same as it is in edit mode.
Javascript
function gv_uploadComplete(sender, args) {
var filename = args.get_fileName();
var filext = filename.substring(filename.lastIndexOf(".") + 1);
if (filext == "pdf") {
document.getElementById('<%=Label39.ClientID%>').innerHTML = 'Data Saved Successfully !!';
return true;
} else {
document.getElementById('<%=Label38.ClientID%>').innerHTML = 'Please upload only pdf file !!';
return false;
}
}
ASPX
<asp:GridView ID="gv_docs" runat="server" AutoGenerateColumns="false" CssClass="table table-bordered table-striped" OnRowDataBound="OnRowDataBoundDocs" Style="width: 100%; white-space: nowrap; font-size: 11.50px; letter-spacing: 0.25px; margin-top: 10px;">
<Columns>
<asp:TemplateField HeaderText="#" HeaderStyle-Font-Bold="true" HeaderStyle-Width="20px" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label runat="server" ID="lblsrno" Text=' <%# Container.DataItemIndex + 1 %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="10px" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" AutoPostBack="true" OnCheckedChanged="GvDocsOnCheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkDel" runat="server" CssClass="chkDelcls" AutoPostBack="true" OnCheckedChanged="GvDocsOnCheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Document Type" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Font-Bold="true">
<ItemTemplate>
<asp:Label ID="lbldddoctype" runat="server" Text='<%# Eval("doctype") %>'></asp:Label>
<asp:DropDownList ID="gv_dddoctype" runat="server" Visible="false" Style="width: 100%; min-width: 150px" CssClass="custom-select mb-3 selectnw">
<asp:ListItem Value="ABC">ABC</asp:ListItem>
<asp:ListItem Value="XYZ">XYZ</asp:ListItem>
<asp:ListItem Value="Other">Other</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Font-Bold="true">
<ItemTemplate>
<asp:Label runat="server" ID="lbldocdesc" Text='<%# Eval("docdesc") %>'></asp:Label>
<asp:TextBox ID="txtdocdesc" Style="white-space: nowrap; min-width: 225px" CssClass="form-control" runat="server" Text='<%# Eval("docdesc") %>' Visible="false"></asp:TextBox>
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator3" SetFocusOnError="true" Display="Dynamic" ControlToValidate="txtdocdesc" ValidationGroup="gv_rfdoc" ForeColor="red" Font-Size="11px" Style="letter-spacing: 1px"><i class="fa fa-exclamation-triangle"></i> Required!</asp:RequiredFieldValidator>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Upload" ControlStyle-CssClass="viscol" HeaderStyle-CssClass="viscol" ItemStyle-CssClass="viscol">
<ItemTemplate>
<asp:Label runat="server" ID="lblfudoc" Text='<%# Eval("fudoc") %>'></asp:Label>
<asp:TextBox ID="txtfudoc" AutoFocus="true" Style="min-width: 100px; white-space: nowrap" CssClass="form-control" runat="server" Text='<%# Eval("fudoc") %>' Visible="false"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Download/Upload" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Font-Bold="true">
<ItemTemplate>
<asp:Label runat="server" ID="lblfudocx">
<asp:UpdatePanel ID="UpdatePanel4" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:LinkButton ID="btnforcedownload" runat="server" OnClick="btnforcedownload_Click" CommandArgument='<%# Eval("fudoc") + "," + Convert.ToString(Eval("dcno")) %>'> <i class="fa fa-download"></i> </asp:LinkButton>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnforcedownload" />
</Triggers>
</asp:UpdatePanel>
</asp:Label>
<asp:Panel ID="uplupload" runat="server" Visible="false" Style="margin-top: 5px;">
<div class="form-group">
<ajax:AsyncFileUpload ID="gv_AsyncFileUpload" ClientIDMode="AutoID" CssClass="filegrid" OnClientUploadComplete="gv_uploadComplete" OnUploadedComplete="gv_fileUploadComplete" Visible=" true" CompleteBackColor="White" Width="100%" runat="server" UploaderStyle="Traditional" UploadingBackColor="White" ThrobberID="imgLoad" />
</div>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="View" HeaderStyle-HorizontalAlign="Left" HeaderStyle-Font-Bold="true">
<ItemTemplate>
<asp:Label runat="server" ID="lbldocpath" Text='<%# "documents\" + Eval("fudoc")%>' Style="color: #ffffff; display: none"></asp:Label>
<asp:LinkButton runat="server" OnClick="btnfileview_Click" CommandArgument='<%# Eval("fudoc") + "," + Convert.ToString(Eval("dcno")) %>' ID="btnfileview" ToolTip="View PO"> <i class="fa fa-eye"></i> </asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DC No" ControlStyle-CssClass="viscol" HeaderStyle-CssClass="viscol" ItemStyle-CssClass="viscol" >
<ItemTemplate>
<asp:Label runat="server" ID="lbldcno" Text='<%# Eval("dcno") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<div class="col-sm-12" style="float: left; text-align: left">
<asp:Button ID="gv_docs_btnUpdate" runat="server" CssClass="btn btn-primary btn-xs" Text="SAVE" Style="margin-bottom: 15px; background-color: #949494; color: #ffffff; border: 1px solid #949494" ValidationGroup="gv_rfdoc" OnClick="gv_docs_Update" Visible="false" />
<asp:Button ID="gv_docs_btnDelete" runat="server" CssClass="btn btn-primary btn-xs" OnClick="gv_docs_Delete" Style="margin-bottom: 15px; background-color: #949494; color: #ffffff; border: 1px solid #949494" OnClientClick="return confirm('Are you sure to delete the document ?')" Text="DELETE" Visible="false" />
<asp:Button ID="btnRefresh" Text="" runat="server" Style="display:none" />
Aspx.vb
Protected Sub gv_fileUploadComplete(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim gv_AsyncFileUpload As AjaxControlToolkit.AsyncFileUpload = CType(sender, AjaxControlToolkit.AsyncFileUpload)
Dim t_dext As String = System.IO.Path.GetExtension(gv_AsyncFileUpload.FileName)
Dim rowIndex As String = (CType((CType(sender, Control)).NamingContainer, GridViewRow)).RowIndex
Dim row As GridViewRow = gv_docs.Rows(rowIndex)
If t_dext.ToLower() = ".pdf" Then
Dim gv_dddoctype As DropDownList = TryCast(row.FindControl("gv_dddoctype"), DropDownList)
Dim txtdocdesc As TextBox = TryCast(row.FindControl("txtdocdesc"), TextBox)
Dim lbldcno As Label = TryCast(row.FindControl("lbldcno"), Label)
Dim t_filename As String = txtorno.Text + lbldcno.Text
Dim newfilename As String = t_filename & System.IO.Path.GetExtension(gv_AsyncFileUpload.FileName)
gv_AsyncFileUpload.SaveAs(Server.MapPath("documents/") & newfilename)
Dim t_text As String = Server.MapPath("documents/") & newfilename
'Public Sub EditDocsWithFile(ByVal t_dtyp As String, t_desc As String, ByVal t_text As String, ByVal t_orno As String, t_dcno As String)
crud.EditDocsWithFile(gv_dddoctype.SelectedValue, txtdocdesc.Text, t_text, txtorno.Text, lbldcno.Text)
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "success", "top.$get(""" & Label39.ClientID & """).innerHTML ='Data Saved Successfully !!';", True)
' ClearContents(CType(sender, Control))
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "error", "top.$get('" & Label38.ClientID & "').innerHTML ='';", True)
Dim chkDel As CheckBox = TryCast(row.FindControl("chkDel"), CheckBox)
If chkDel.Checked Then
chkDel.Checked = False
chkDel.AutoPostBack = True
UpdatePanel3.Update()
GetOrdderDocGrid(txtorno.Text)
End If
Else
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "error", "top.$get('" & Label39.ClientID & "').innerHTML ='';", True)
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "error", "top.$get('" & Label38.ClientID & "').innerHTML ='Please upload only pdf file !!';", True)
Dim chkDel As CheckBox = TryCast(row.FindControl("chkDel"), CheckBox)
chkDel.Checked = True
chkDel.AutoPostBack = True
UpdatePanel3.Update()
gv_btnUpdate.Visible = True
gv_btnDelete.Visible = True
End If
Catch ex As Exception
Me.log.LogError(ex)
End Try
End Sub