如果表格单元格的数据大于其高度,则建立链接

时间:2012-10-18 11:19:00

标签: c# asp.net html css

我正在从代码后面创建表来显示每周报告。它工作正常。但是现在如果表格单元格中的数据很大,就会出现问题。我希望在单元格中建立链接,如果数据较大以适合表格单元格,并且onclick在弹出窗口中显示单元格的整个数据。或类似的东西。我尝试溢出滚动,但它看起来很糟糕。 我生成表的代码是: -

private void TaskTable(TaskSearch search)
{

    _empList = _objDBL.GetEmpList(ddlCategory.SelectedValue);
    Label heading = new Label();
    heading.Text ="Task Report from "+search.FromDate.ToString("dd MMM,yyyy")+" to "+search.ToDate.ToString("dd MMM,yyyy");
    heading.Attributes.Add("class", "weekheading");

    divTaskTable.Controls.Add(heading);
    Session["Lable"] = heading;
    Table table = new Table();
    TableRow row;
    TableCell cell;
    TableHeaderRow headerRow = new TableHeaderRow();
    TableHeaderCell headerCell;
    table.CssClass = "grid-view";

    headerCell = new TableHeaderCell();
    headerCell.Text = "Emp Name";
    headerRow.Cells.Add(headerCell);
    headerCell = new TableHeaderCell();
    headerCell.Text = "Monday";
    headerRow.Cells.Add(headerCell);
    headerCell = new TableHeaderCell();
    headerCell.Text = "Tuesday";
    headerRow.Cells.Add(headerCell);
    headerCell = new TableHeaderCell();
    headerCell.Text = "Wednesday";
    headerRow.Cells.Add(headerCell);
    headerCell = new TableHeaderCell();
    headerCell.Text = "Thursday";
    headerRow.Cells.Add(headerCell);
    headerCell = new TableHeaderCell();
    headerCell.Text = "Friday";
    headerRow.Cells.Add(headerCell);
    headerCell = new TableHeaderCell();
    headerCell.Text = "Saturday";
    headerRow.Cells.Add(headerCell);

    table.Rows.Add(headerRow);
    for (int i = 0; i < _empList.Count; i++)
    {
        int m=1;
        row = new TableRow();
        cell = new TableCell();
        cell.Text = _empList[i].Name;
        row.Cells.Add(cell);
        search.EmpId = _empList[i].Id;
        _taskList = _objDBL.GetSearchedTaskList(search);
        string[] months = System.Globalization.DateTimeFormatInfo.InvariantInfo.DayNames;

        for (int j = 0; m < months.Count() && j<_taskList.Count; m++)
        {
            if (_taskList[j].Date.DayOfWeek.ToString().Equals(months[m]))
            {
                cell = new TableCell();
                cell.Text = _taskList[j++].TodaysTask;
                row.Cells.Add(cell);
            }
            else
            {
                cell = new TableCell();
                cell.Text = "-";
                row.Cells.Add(cell);
            }

        }
        for (; m < 7; m++)
        {
            cell = new TableCell();
            cell.Text = "-";
            row.Cells.Add(cell);
        }
        table.Rows.Add(row);
    }
    divTaskTable.Controls.Add(table);
    Session["Table"] = table;
} 

1 个答案:

答案 0 :(得分:2)

这是我在我们的网站上进行产品描述的方式,文本大于75个字符,它生成一个较短的文本,然后是一个完整描述链接。我相信你可以修改它代码。我的网站是在VB.NET中,这个代码用于gridview控件,但你得到了它的要点。

 If descLength >= 75 then
      CType(row.FindControl("shortDesc"), Label).Text = CType(row.FindControl("labelDesc"), Label).Text.Substring(0, 74) & "... <a href='/detailsfp.aspx?prodid=" & productIDM & "'>Full Description</a>"
 End If