English 中文(简体)
在编码背后(ASPX网页)中建立一个表格(浏览器和栏目)。
原标题:Build a table (with rows & columns) in code-behind (ASPX page)

在业余科室一页的密码中,我几乎没有雇员详情(可从外部数据来源查阅)。 最后,我要以以下方式发言。 下面的显示可能不正确,但只是一张带有头盔/col门方法的模拟表格。

___________________________________________________________________________________
|                        DEPT        | HR                                          | |__________________________________________________________________________________|
|     Employee Image                 | Emp Name       | Hire Date                  |
|____________________________________|_____________________________________________|
|        Steve.gif                   | Steve Jobs     |  22/05/1979                |
|____________________________________|_____________________________________________|
|        Mark.gif                    | Mark Miller    |  22/05/1949                |
|____________________________________|_____________________________________________|
|                        DEPT        | Operations                                  | |__________________________________________________________________________________|
|     Employee Image                 | Emp Name       | Hire Date                  |
|____________________________________|_____________________________________________|

这些数据是从各种数据来源收集的,最后可在编码中查阅。 我想以上述方式展示。

什么是最佳办法? 我想形成一种控制,并增加所有这些价值。 最后,我将把四舍五入到一页。

目前,我正在尝试办法,但想知道是否有任何更好的办法。

Please share your views and exaamples. _

最佳回答

The best approach in my opinion, would be to use a Repeater like this:

<asp:Repeater ID="rpt" runat="server" OnItemDataBound="rpt_RowDataBound">
        <ItemTemplate>
            <table runat="server" style="color: White; background-color: #3A4F63;" visible="false"
                id="headerTable">
                <tr>
                    <td colspan="3" align="center">
                        <asp:Label ID="headerTitle" runat="server"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td style="width: 200px; background-color: #3A4F63; color: White;">
                        Image 
                    </td>
                    <td style="width: 200px;">
                        Name
                    </td>
                    <td style="width: 200px;">
                        Hire Date
                    </td>
                </tr>
            </table>
            <!-- These are the actual data items -->
            <!-- Bind to your specific properties i.e. Employees. -->
            <table>
                <tr>
                    <td style="width: 200px;">
                        <asp:Image ID="img" runat="server" ImageUrl= <%#Eval("ImageUrl") %> ></asp:Image>
                    </td>
                    <td style="width: 200px;">
                        <asp:Label ID="lblName" runat="server" Text= <%#Eval("Name") %> ></asp:Label>
                    </td>
                    <td style="width: 200px;">
                        <asp:Label ID="lblHireDate" runat="server" Text= <%#Eval("HireDate") %> ></asp:Label>
                    </td>
                </tr>
            </table>
        </ItemTemplate>
    </asp:Repeater>

接着,就你们的法典而言,例如:

private string currentDepartment =string.Empty;

protected void rpt_RowDataBound(object sender, RepeaterItemEventArgs e)
{

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
        //Binding to Employee object.
        if (currentDepartment!= (e.Item.DataItem as Employee).Department) {
        currentDepartment = (e.Item.DataItem as Employee).Department;
            e.Item.FindControl("headerTable").Visible = true;
            (e.Item.FindControl("headerTitle") as Label).Text = (e.Item.DataItem as Employee).Department;
        }
            else {
            e.Item.FindControl("headerTable").Visible = false;
        }
    }
}

您需要把电网连接到<代码>。 清单和编号;Employee>。

public class Employee
{
   public string Department {get;set;}
   public string ImageUrl {get;set;}
   public DateTime HireDate {get;set;}
   public string Name {get;set;}
}

<>But,必须事先由该部下令接受约束。

www.un.org/Depts/DGACM/index_spanish.htm 复制品()

private void bindGridView()
{
    List<Employee> emps = new List<Employee>();
    for (int i = 0; i < 5; i++)
    {
        Employee e = new Employee();
        if (i % 2 == 0)
        {
            e.Department = "Human resources";
            e.HireDate = DateTime.Now.AddDays(-i);
            e.ImageUrl = @"http://www.freedigitalphotos.net/images/gal_images/av-_146.jpg";
        }
        else
        {
            e.Department = "Information Technology";
            e.HireDate=DateTime.Now.AddMonths(-i);
            e.ImageUrl = "http://www.freedigitalphotos.net/images/gal_images/av-_314.jpg";

        }

        e.Name = "Employee " + i;
        emps.Add(e);

    }
    rpt.DataSource = emps.OrderBy(x=>x.Department);
    rpt.DataBind();
}

<<>Produces>/strong>

“enterography

问题回答

你们是否想生动地这样做? 你们今后会不时地对其进行编辑。 为什么在您的标志中不做普通的HtmlTable,将一些Labels和图像带上,然后在密码背后将其填入? 是否有任何特别原因?

You have a couple of options.

一种办法是将所有不同的数据合并成单一的数据表,由你制作,并约束你们的数据来源。

另一种做法是简单地做你所建议的事,并放弃相关信息。

A third is to define the table in your aspx file and use asp:label controls. In your code behind populate the label controls from your various data sources.

Given those options I d probably go with the third one. Sounds easiest to reconfigure / change the display of when you need to.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签