我已经添加了一个指向我现有表格单元格的超链接,但我得到了两次电影名称。另外,我想添加其他表格单元格作为导演,演员和Filmyear等超链接。我该怎么做?
我的表格单元格如下:
tc = GetTableCell(film.FilmName);
tr.Cells.Add(tc);
tc = GetTableCell(film.Directors[0].PersonName);
tr.Cells.Add(tc);
tc = GetTableCell(film.Actors[0].PersonName);
tr.Cells.Add(tc);
tc = GetTableCell(film.FilmYear);
tr.Cells.Add(tc);
我的HyperLink代码如下:
HyperLink link = new HyperLink();
link.NavigateUrl = "https://www.imdb.com/title/tt4154756/";
link.Text = film.FilmName;
tc.Controls.Add(link);
tr.Cells.Add(tc);
答案 0 :(得分:0)
试试这个。
private void CreateTable()
{
Table table = new Table();
TableRow tr = new TableRow();
//film name
tr.Cells.Add(GetTableCell("Film Name"));
//director
tr.Cells.Add(GetTableCell("Director Name"));
//actor
tr.Cells.Add(GetTableCell("Actor Name"));
//film year
tr.Cells.Add(GetTableCell("Film Year"));
//film link
HyperLink link = new HyperLink();
link.NavigateUrl = "https://www.imdb.com/title/tt4154756/";
link.Text = "Film Name";
tr.Cells.Add(GetTableCell(link));
table.Rows.Add(tr);
}
//returns new table cell with text content
private TableCell GetTableCell(string text)
{
TableCell tc = new TableCell();
tc.Text = text;
return tc;
}
//returns new table cell with hyperlink
private TableCell GetTableCell(HyperLink link)
{
TableCell tc = new TableCell();
tc.Controls.Add(link);
return tc;
}