I have a GridView control,inside of which I am having a file upload control with a button to upload files, Each FileControl have its own upload button, I am uploading files using RowCommand Event.Now I have to show progress bar of file upload control which I have implemented like in this link's 3rd answer Link with some modification in JS
The problem I am facing is that if I click on 2nd Row's upload button of GridView,Its validating only Row's Control.
This is my Grid View
<asp:GridView ID="Grid1" runat="server" AutoGenerateColumns="false" OnRowDataBound="Grid1_RowDataBound"
OnRowCommand="Grid1_RowCommand" OnRowDeleting="Grid1_RowDeleting"
CssClass="table">
<Columns>
<asp:TemplateField HeaderText="Files" ItemStyle-HorizontalAlign="Left" HeaderStyle-CssClass="GridViewHeader">
<ItemTemplate>
<asp:FileUpload ID="File1" runat="server" Width="98%" CssClass="filestat" />
<asp:Button ID="btnuploadfiles" runat="server" CommandName="upload" Text="Upload" OnClientClick="return ProgressBar('File1')" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and my JS code
function ProgressBar(Id) {
var fileControl = GetClientID(Id).attr("id");
if (document.getElementById(fileControl).value != "") {
$("#divUpload").fadeIn("slow");
$('#popup_box').fadeIn("slow");
document.getElementById("divUpload").style.height = document.body.clientHeight + 'px';
id = setInterval("progress()", 20);
return true;
}
else {
alert("Select a file to upload");
return false;
}
}
//This function returns me ClientID of the server control
function GetClientID(id, context) {
var el = $("#" + id, context);
if (el.length < 1)
el = $("[id$=_" + id + "]", context);
return el;
}
I also have tried setting OnClientClick from RowDataBound,but its still validating only first Row.
protected void Grid1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
var btnupd = (Button)e.Row.FindControl("btnuploadfiles");
btnupd.OnClientClick = "return ProgressBar('File1')";
}
}