如何在动态表上创建col span或row span。 [英] How can I create col span or row span on dynamic table.

查看:105
本文介绍了如何在动态表上创建col span或row span。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用c#创建了一个动态表。如何使用文本框在动态表格上设置一个colspan?



例如,如果我在文本框中放置一个值3并单击Apply Span按钮,那么动态表的colspan应相应更改。



我是c#的新手,请帮助



谢谢。



我的尝试:



<

I have created a dynamic table using c#. How do I set a colspan on the dynamic table using a textbox?

For example if I place a value 3 in the text box and click on Apply Span button then the colspan of a dynamic table should change accordingly.

I am new to c#, pls help

Thanks.

What I have tried:

<

    public partial class WebForm1 : System.Web.UI.Page
    {
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    public void CreateRuntime_Table()
    {
        int tblRows = int.Parse(txtrow.Text);
        int tblCols = int.Parse(txtcol.Text);

        Table tbl = new Table();
        tbl.BorderWidth = 3;
        tbl.BorderStyle = BorderStyle.Solid;
        tbl.ID = "myTable";

        for (int i = 1; i <= tblRows; i++)
        {

            TableRow tr = new TableRow();
            for (int j = 1; j <= tblCols; j++)
            {
                TableCell tc = new TableCell();
                TextBox txtbox = new TextBox();
                txtbox.Text = "Test Row:" + i + "Test Col:" + " " + j;
                //Add the control to the table cell
                tc.Controls.Add(txtbox);
                tr.Controls.Add(tc);
            }

            tbl.Rows.Add(tr);
        }

        form1.Controls.Add(tbl);
    }

    protected void Unnamed_Click(object sender, EventArgs e)
    {
        CreateRuntime_Table();
    }

   
Html Here:

<pre>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server"> 
    <title></title>
    </head>
    <body>
    <link href="StyleSheet1.css" rel="stylesheet" />
    <form id="form1" runat="server">
    <div>
     <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
        <table>
            <caption>Creating a dyanamic Table</caption>
            <tr>
                <td>
                    Row:       <asp:TextBox ID="txtrow" 

    placeholder="No of Rows Here" runat="server" AutoCompleteType="Disabled" > 
    </asp:TextBox>
                    <br />
                    <br />
                </td>
            </tr>
            <tr>
                <td>
                    
                    Coloum: <asp:TextBox ID="txtcol" placeholder="No of Coloums Here" 

      runat="server" AutoCompleteType="Disabled"></asp:TextBox>
                    <br /> <br />
                </td>
           </tr>
            <tr>
                <td>
                     <asp:Button Text="Create Table" runat="server" CssClass="button" 

       OnClick="Unnamed_Click"/>
                </td>
            </tr>
        </table>
        <br />

            <h4>Appying Row/Col span on Dynamic Tabes</h4>
            Colspan:   <asp:TextBox ID="txtcolspan" placeholder="Colspan 
     Here" runat="server" AutoCompleteType="Disabled"></asp:TextBox>
            <span></span>
            <asp:Button Text="Apply Span" runat="server" CssClass="button" 

    OnClick="Unnamed2_Click"/>
            <br />
            <br />
            Rowspan: <asp:TextBox ID="txtrowspan" placeholder="Rowspan Here" 

    runat="server" AutoCompleteType="Disabled"></asp:TextBox>
            <span></span>
            <asp:Button Text="Apply Span" runat="server" CssClass="button" 

    OnClick="Unnamed3_Click"/>       
         </div>
    </form>
   </body>
   </html>

推荐答案

TableCell 有一个 ColumnSpan RowSpan 属性。



只需在回发时重新生成表时设置这些属性。
The TableCell has a ColumnSpan and RowSpan attributes that you can set.

Just set those properties when regenerating your table on postbacks.


这篇关于如何在动态表上创建col span或row span。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆