简体   繁体   English

Asp.net Web窗体垂直表

[英]Asp.net Web Forms Vertical Table

I have this code in my page in my ASP.New WebForms Project: 我的ASP.New WebForms项目的页面中有以下代码:

 private void populateTable(MySqlDataReader mySqlDataReader)
        {
            foreach (DbDataRecord rowData in mySqlDataReader)
            {
                TableRow tr = new TableRow();

                TableCell cell2 = new TableCell();
                cell2.Text = rowData.GetInt32(rowData.GetOrdinal("truck_id")).ToString();
                tr.Cells.Add(cell2);

                TableCell cell3 = new TableCell();
                cell3.Text = rowData.GetString(rowData.GetOrdinal("registration_no")).ToString();
                tr.Cells.Add(cell3);

                TableCell cell4 = new TableCell();
                cell4.Text = rowData.GetString(rowData.GetOrdinal("make")).ToString();
                tr.Cells.Add(cell4);

                TableCell cell5 = new TableCell();
                cell5.Text = rowData.GetString(rowData.GetOrdinal("model")).ToString();
                tr.Cells.Add(cell5);

                TableCell cell1 = new TableCell();
                cell1.Text = rowData.GetString(rowData.GetOrdinal("engine_no")).ToString();
                tr.Cells.Add(cell1);

                TableCell cell6 = new TableCell();
                cell6.Text = rowData.GetString(rowData.GetOrdinal("chassis_no")).ToString();
                tr.Cells.Add(cell6);

                TableCell cell7 = new TableCell();
                cell7.Text = rowData.GetString(rowData.GetOrdinal("driver_name")).ToString();
                tr.Cells.Add(cell7);

                TableCell cell8 = new TableCell();
                cell8.Text = rowData.GetString(rowData.GetOrdinal("driver_contact_no")).ToString();
                tr.Cells.Add(cell8);

                TableCell cell9 = new TableCell();
                cell9.Text = rowData.GetString(rowData.GetOrdinal("status")).ToString();
                tr.Cells.Add(cell9);

                tbl_TruckData.Rows.Add(tr);
            }
 }

How can O intergrate it to Vertical Table? O如何将其集成到“垂直表”中?

Truck No                  1
Registration No           AA0-1234

The current out is an Horizontal Table like this: 当前输出是一个水平表,如下所示:

Truck No      Registration No     Make
   1             AA0-1234         MAN

Other question is it possible to embbed a <asp:Label> inside a <td> element? 另一个问题是否可能在<td>元素内嵌入<asp:Label>

For example: 例如:

<td> Make: </td>
<td> <asp:Label id = "TMake" runat="server"/></td>(this)

I've tried it but there's no out put in (this) 我已经尝试过了,但是没有投入

How can i intergrate it to Vertical Table. 我如何将其集成到垂直表。

You can start a new row each time: 您可以每次开始新的一行:

TableRow tr = new TableRow();
TableCell cell2 = new TableCell();
cell2.Text = rowData.GetInt32(rowData.GetOrdinal("truck_id")).ToString();
tr.Cells.Add(cell2);
tbl_TruckData.Rows.Add(tr);

tr = new TableRow();
TableCell cell3 = new TableCell();
cell3.Text = rowData.GetString(rowData.GetOrdinal("registration_no")).ToString();
tr.Cells.Add(cell3);
tbl_TruckData.Rows.Add(tr);

or look into more sophisticated binding controls like GridView 或研究更复杂的绑定控件,例如GridView

Is it possible to embbed a <asp:Label> inside a <td> element? 是否可以在<td>元素中嵌入<asp:Label>

Sure - you may not be setting the Text property - either in binding or in server-side code. 当然-您可能没有在绑定中或在服务器端代码中设置Text属性。

this.TMake.Text = make;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM