/// <summary> /// generate .pdf /// </summary> /// <param name="path">path of document</param> /// <param name="filename">name of .pdf documen</param> /// <param name="download">is downloadable</param> /// <param name="text">text place in .pdf</param> private void generatepdf(string path, string filename, bool download, string text) { var document = new document(); try { if (download) { pdfwriter.getinstance(document, response.outputstream); } else { pdfwriter.getinstance(document, new filestream(path + filename, filemode.create)); } // generates grid first stringbuilder strb = new stringbuilder(); document.open(); if (text.length.equals(0)) // export text { bindmygrid(); using (stringwriter swriter = new stringwriter(strb)) { using (htmltextwriter htwriter = new htmltextwriter(swriter)) { gridview1.rendercontrol(htwriter); } } } else // export grid { strb.append(text); } // read grid html 1 one , add document object using (textreader sreader = new stringreader(strb.tostring())) { // #### error on next line list<ielement> list =htmlworker.parsetolist( sreader, new stylesheet());** //itextsharp.text.html.simpleparser.htmlworker.parsetolist(sreader, null) foreach (ielement elm in list) { document.add(elm); } } } catch (exception ee) { lblmessage.text = ee.tostring(); } { document.close(); } } /// <summary> /// binds grid. /// </summary> private void bindmygrid() { // sql paging. in production write in stored procedure string sql = "select * ( " + " select samplefortutorials.*, row_number() on (order autoid desc) rownum " + " samplefortutorials) addresslist " + " rownum between @startrowindex , (@startrowindex + @pagesize) - 1 " + "order autoid desc"; datatable table = new datatable(); int totalcount = 0; // data using (oledbconnection conn = new oledbconnection(_connstr)) { using (oledbcommand cmd = new oledbcommand(sql, conn)) { cmd.commandtype = commandtype.text; oledbparameter p = new oledbparameter("@startrowindex", sqldbtype.int); p.value = _startrowindex + 1; cmd.parameters.add(p); p = new oledbparameter("@pagesize", sqldbtype.int); p.value = _pagesize; cmd.parameters.add(p); conn.open(); // data first using (oledbdataadapter ad = new oledbdataadapter(cmd)) { ad.fill(table); } // total count of records sql = "select count(autoid) samplefortutorials"; cmd.parameters.clear(); cmd.commandtext = sql; object obj = cmd.executescalar(); totalcount = convert.toint32(obj); conn.close(); } } // bind data grid gridview1.datasource = table; gridview1.databind(); }
i getting error on indicated line. how solve this? want create dynamic pdf dynamically binded gridview , view in iframe.
you need cast list generic type. use .cast().tolist()
Comments
Post a Comment