asp.net - How to generate a print preview in a single button click in report viewer? -
this aspx page..................
<asp:panel id="updatepanel1" runat="server" visible="false" > <rsweb:reportviewer id="reportingforprintingreportviewer" runat="server" width="100%" height="100%" font-names="verdana" font-size="8pt" interactivedeviceinfos="(collection)" waitmessagefont-names="verdana" waitmessagefont-size="14pt"> <localreport reportpath="report.rdlc"> <datasources> <rsweb:reportdatasource datasourceid="objectdatasource2" name="dataset1" /> </datasources> </localreport> </rsweb:reportviewer> <asp:objectdatasource id="objectdatasource2" runat="server" selectmethod="getdata" typename="dataset1tableadapters.tbltotalfeetableadapter"> </asp:objectdatasource> </asp:panel> <asp:button id="btnsubmit" runat="server" text="submit" width="150px" onclick="btnsubmit_click" /> <asp:button id="btnreset" runat="server" text="reset" width="150px" /> <asp:button id="btncreatebill" runat="server" text="createbill" width="150px" onclick="btncreatebill_click"/> <asp:popupcontrolextender id="btncreatebill_popupcontrolextender" offsetx="-1100" offsety="115" runat="server" dynamicservicepath="" enabled="true" extendercontrolid="" targetcontrolid="btncreatebill" popupcontrolid="updatepanel1"> </asp:popupcontrolextender>
this cs page
protected void btncreatebill_click(object sender, eventargs e) { displayreport(); updatepanel1.visible = true; } private datatable totalinfodata() { try { //dataclassesdatacontext db = null; //db = new dataclassesdatacontext(); //var s = p in db.tbltotalfeess // p.class == classdropdownlist.selecteditem.value && p.studentid == convert.toint32(studentnamedropdownlist.selectedvalue) // select p; //datatable dt = new datatable(); //sqlhelper sqhlpr = new sqlhelper(); //sqhlpr.sqltext = "select * tbltotalfee class='" + classdropdownlist.selecteditem.value + "'" + "and studentid='" + studentnamedropdownlist.selectedvalue + "'"; //datatable dt = sqhlpr.getdatatable(false); //return dt; try { // open sql connection sqlconnection sqlcon = new sqlconnection(@"data source=pratikpc;initial catalog=dbbilling2.0;integrated security=true"); sqlcon.open(); // create command sqlcommand sqlcomm = new sqlcommand(); sqlcomm.connection = sqlcon; sqlcomm.commandtype = commandtype.text; sqlcomm.commandtext = "select * tbltotalfee class='" + classdropdownlist.selecteditem.value + "'" + "and studentid='" + studentnamedropdownlist.selectedvalue + "'"; // create instance of northwind datasetxsd dataset1.tbltotalfeedatatable dtbl = new dataset1.tbltotalfeedatatable(); // set data commands sqldataadapter sqlda = new sqldataadapter(sqlcomm); sqlda.fill(dtbl); // fill data in northwinddataset object. return dtbl; } catch (exception ex) { throw new exception(ex.message); } } catch (exception ex) { throw new exception(ex.message); } } private void displayreport() { try { // clear data source reportingforprintingreportviewer.localreport.datasources.clear(); // set datasource report // first parameter - report dataset name // second parameter - datasource object i.e datatable reportingforprintingreportviewer.localreport.datasources.add(new reportdatasource("dataset1", totalinfodata())); // or set report path reportingforprintingreportviewer.localreport.reportpath = httpcontext.current.server.mappath("~/report.rdlc"); // refresh , display report reportingforprintingreportviewer.localreport.refresh(); } catch (exception ex) { throw new exception(ex.message); } }
i have click btncreatebill twice generate report viewer. why?? , how can generate report viewer in single click of button??it's urgent can suggest me anything.
are call data method(your data source load method ) in inside of !ispostback ?
for this
protected void page_load(object sender, eventargs e) { if (!page.ispostback) { getdata()// data source load method } }
Comments
Post a Comment