不能将数组列表类型隐式转换为 generic.list
本文关键字:list generic itextsharp text element 转换 数组 列表 类型 不能 | 更新日期: 2023-09-27 18:21:55
/// <summary>
/// generate the .pdf
/// </summary>
/// <param name="path">path of the document</param>
/// <param name="fileName">name of the .pdf documen</param>
/// <param name="download">is this downloadable</param>
/// <param name="text">text to place in the .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 the grid first
StringBuilder strB = new StringBuilder();
document.Open();
if (text.Length.Equals(0)) // export the text
{
BindMyGrid();
using (StringWriter sWriter = new StringWriter(strB))
{
using (HtmlTextWriter htWriter = new HtmlTextWriter(sWriter))
{
GridView1.RenderControl(htWriter);
}
}
}
else // export the grid
{
strB.Append(text);
}
// now read the Grid html one by one and add into the document object
using (TextReader sReader = new StringReader(strB.ToString()))
{
// #### error on the 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();
}
finally
{
document.Close();
}
}
/// <summary>
/// Binds my grid.
/// </summary>
private void BindMyGrid()
{
// sql for paging. In production write this in the Stored Procedure
string sql = "SELECT * FROM ( " +
" Select SampleForTutorials.*, ROW_NUMBER() OVER (ORDER BY AutoId DESC) as RowNum " +
" FROM SampleForTutorials) as AddressList " +
" WHERE RowNum BETWEEN @startRowIndex AND (@startRowIndex + @pageSize) - 1 " +
"ORDER BY AutoId DESC";
DataTable table = new DataTable();
int totalCount = 0;
// get the data now
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();
// get the data first
using (OleDbDataAdapter ad = new OleDbDataAdapter(cmd))
{
ad.Fill(table);
}
// get the total count of the records now
sql = "select count(AutoId) from SampleForTutorials";
cmd.Parameters.Clear();
cmd.CommandText = sql;
object obj = cmd.ExecuteScalar();
totalCount = Convert.ToInt32(obj);
conn.Close();
}
}
// bind the data to the grid
GridView1.DataSource = table;
GridView1.DataBind();
}
我在指示的行上收到错误。 我该如何解决这个问题? 我想从动态绑定的网格视图和 iframe 中的视图创建一个动态 PDF。
您需要将列表强制转换为泛型类型。用。Cast((。到列表((