Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET Sharepoint
I have multiple file upload control in asp.net grid view,i want to clear/reset file upload control when wrong file selection.
 
fileupload1 btnReset1
fileupload2 btnReset2
...
 
when i click btnReset2 then only clear value for fileupload2

How can i do this using java script.
Please help me
 
Thank you all in advance
Posted 8-Jul-12 22:01pm
Comments
Sanjay Kunjam at 9-Jul-12 4:24am
   
Hi,
you can filter your file selection in upload event. You don't need to clear when selected file is wrong its automatically clears fileupload1 control. Why you want to out an extra button for clear?
jignesh,surat at 9-Jul-12 9:29am
   
Hi... Sanjay Kunjam
Thanks for reply.
but i need to cancel the selected file that’s why I have put reset button on that buttons click event I’m clearing that rows file upload control textbox. Currently in my code control is not clearing but I want to clear specific file upload control my code is as follows (I’m doing this by using JS).

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

JS Code:-
<script type="text/javascript">
        function hi(ob) {
            debugger;
            var grid = document.getElementById("<%= GridView1.ClientID %>");
            var inputs = grid.getElementsByTagName("input");
            var fileUpload;
            var strRowNo = ob.id.toString().split("_")[3];//get row number
            alert(strRowNo);
            for (var i = 0; i < inputs.length; i++) {
                if (inputs[i].type == "file") {
                    fileUpload = inputs[i];
                    if (i == strRowNo) {
                        fileUpload.value = "";
                    }
                }
            }
        }
    </script>
 

Aspx Code:-
  <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
                <Columns>
                    <asp:BoundField DataField="A" HeaderText="A" />
                    <asp:BoundField DataField="B" HeaderText="B" />
                    <asp:BoundField DataField="C" HeaderText="C" />
                    <asp:TemplateField HeaderText="File">
                        <ItemTemplate>
                            <div id="fuDiv" runat="server">
                                <asp:FileUpload ID="fupFile" runat="server" />
                            </div>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Reset">
                        <ItemTemplate>
                            <asp:Image ID="ibtnReset" runat="server" onClick="javascript:hi(this);" />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </ContentTemplate>
    </asp:UpdatePanel>
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 459
1 Nirav Prabtani 338
2 Abhinav S 170
3 PIEBALDconsult 160
4 Pikoh 140
0 OriginalGriff 7,640
1 Sergey Alexandrovich Kryukov 6,836
2 Maciej Los 3,919
3 Peter Leow 3,698
4 CHill60 2,742


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 10 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100