c# - Why doesn't row command properly work? -
i have download function getting called in rowcommand of gridview. works when click stops working if click(call) function in rowcommand. doesn't throw exception. tried debugging every step no luck.
why ?
download function:
public void downloadfile(string filename) { try { string filepath = filename; string fullfilepath = server.mappath("../../siteimages/bpa/" + filepath); response.clear(); response.clearheaders(); response.clearcontent(); response.addheader("content-disposition", "attachment; filename=\"" + path.getfilename(fullfilepath) + "\""); response.contenttype = contenttype; response.transmitfile(fullfilepath); }
rowcommand:
protected void grdviewuploadedmaterialother_rowcommand(object sender, gridviewcommandeventargs e) { try { if (e.commandname == "download") { mdlimgpreview.hide(); string filename = convert.tostring(e.commandargument); downloadfile(filename); return; } if (e.commandname == "view") { imgpreviewed.imageurl = "../../siteimages/bpa/" + e.commandargument.tostring(); mdlimgpreview.show(); } } catch (exception ex) { resultlabel.resultlabelattributes(ex.message, projectusercontrols.enums.resultlabel_color.red); } { resultpanel.controls.add(resultlabel); }
rowdatabound: register button
protected void grdviewuploadedmaterialother_rowdatabound(object sender, gridviewroweventargs e) { try { linkbutton lb = e.row.findcontrol("btnlinkdownload") linkbutton; registerdownloadbutton(lb); } catch (exception ex) { resultlabel.resultlabelattributes(ex.message, projectusercontrols.enums.resultlabel_color.red); } { resultpanel.controls.add(resultlabel); } }
registration function:
public void registerdownloadbutton(linkbutton lb) { try { if (lb != null) scriptmanager.getcurrent(this).registerpostbackcontrol(lb); } catch (exception ex) { resultlabel.resultlabelattributes(ex.message, projectusercontrols.enums.resultlabel_color.red); } { resultpanel.controls.add(resultlabel); } }
gridview:
<asp:gridview runat="server" id="grdviewuploadedmaterialother" width="100%" onrowdatabound="grdviewuploadedmaterialother_rowdatabound" onrowcommand="grdviewuploadedmaterialother_rowcommand" headerstyle-backcolor="#99cc99" datakeynames="pk_uploadedmaterialother_id" autogeneratecolumns="false" cssclass="table table-condensed table-bordered table-striped table-responsive"> <pagersettings mode="numeric" /> <pagerstyle horizontalalign="center" cssclass="gvwcasespager" /> <columns> <asp:templatefield headertext="view attachment"> <itemtemplate> <asp:linkbutton id="btnlnkviewattachment" runat="server" text="view" commandargument='<%# eval("materialpath") %>' commandname="view"></asp:linkbutton> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="download"> <itemtemplate> <asp:linkbutton id="btnlinkdownload" runat="server" text='<%# eval("materialpath") %>' commandargument='<%# eval("materialpath") %>' commandname="download"></asp:linkbutton> </itemtemplate> </asp:templatefield> <asp:templatefield headertext="delete"> <itemtemplate> <asp:imagebutton id="btndelete" runat="server" imageurl="~/assets/global/images/delete.png" commandname="cmddelete" commandargument='<%# container.dataitemindex %>' controlstyle-width="20px" controlstyle-height="20px" /> </itemtemplate> </asp:templatefield> </columns> </asp:gridview>
try add updatepanel control gridview solve problem.
refere following code, may you.
<asp:templatefield headertext="download"> <itemtemplate> <asp:updatepanel runat="server" updatemode="conditional" id="fileuploadpanel"> <contenttemplate> <asp:linkbutton id="btnlinkdownload" runat="server" text='<%# eval("materialpath") %>' commandargument='<%# eval("materialpath") %>' commandname="download"></asp:linkbutton> </contenttemplate> <triggers> <asp:postbacktrigger controlid="btnlinkdownload" /> </triggers> </asp:updatepanel> </itemtemplate> </asp:templatefield>
Comments
Post a Comment