c# - how to add upload control in gridview in asp.net -


how add file upload control in item template in grid view.unable file name upload control of gridview.how add file upload control in gridview every row

<asp:gridview runat="server" id="gridviewaddpo" autogenerateeditbutton="false" onrowediting="gridviewaddpo_rowediting" onrowupdating="gridviewaddpo_rowupdating" autogeneratecolumns="false">   <columns>           <asp:templatefield>               <itemtemplate>                   <asp:button id="btn_edit" runat="server" text="edit" commandname="edit" />               </itemtemplate>               <edititemtemplate>                   <asp:button id="btn_update" runat="server" text="update" commandname="update"/>                   <asp:button id="btn_cancel" runat="server" text="cancel" commandname="cancel"/>               </edititemtemplate>           </asp:templatefield>           <asp:templatefield>           <itemtemplate>             <asp:fileupload id="fileupload1" runat="server" />             <asp:button id="button1" runat="server" text="upload" onclick="upload" />           </itemtemplate>       </asp:templatefield>       <asp:templatefield headertext="id">                           <itemtemplate>                               <asp:label id="lbl_id" runat="server" text='<%#eval("id") %>'></asp:label>                           </itemtemplate>         </asp:templatefield>       <columns/> </asp:gridview> 

code behind this:

protected void upload(object sender, eventargs e) {     string filename = path.getfilename(fileupload1.postedfile.filename);//getting errrorhow ot      string contenttype = fileupload1.postedfile.contenttype;     using (stream fs = fileupload1.postedfile.inputstream)     {         using (system.io.binaryreader br = new binaryreader(fs))         {             byte[] bytes = br.readbytes((int32)fs.length);             string constr = configurationmanager.connectionstrings["kernelcs"].connectionstring;             using (sqlconnection con = new sqlconnection(constr)) ..... } 

replace error line below 4 lines

button btn = (button)sender; gridviewrow gvr = (gridviewrow)btn.namingcontainer; fileupload fu = gvr.cells[1].findcontrol("fileupload1") fileupload; string filename = path.getfilename(fu.postedfile.filename); 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -