设置< th>的宽度列表视图中的布局模板中的标签 [英] Set the width of <th> tags in Layout Template in List View

查看:98
本文介绍了设置< th>的宽度列表视图中的布局模板中的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个包含10列的列表视图的aspx 3.5网络表单。  当我做asp工作时,我能够定义列宽列表(例如)width1 = 80,width2 = 100 ...)并自动计算布局的总表格宽度*例如tablewidth
= width1 + width2 。...)&NBSP;这很棒,因为它允许我在一个位置调整列宽并自动调整表格宽度。   当然这是经典的asp所以代码在标记页面(aspx)上,我可以设置< th> 的宽度
。使用< th id =" th1" RUNAT = QUOT;服务器" style ='width:"<%= width1%>" ;;'。 我想在aspx页面上做相同的操作。 但是我似乎无法弄清楚如何做到这一点。 我尝试在页面
类(aspx.cs页面)中设置宽度,但它们似乎没有在html标记中公开,因为它们在asp页面中。 我说我是asp.net的新手吗? 无论如何,我一直在寻找任何解决方案,允许我在一个位置定义所有列宽(在aspx或aspx.cs页面上为
)并轻松调整它们。 

I'm creating an aspx 3.5 web form with a list view that has 10 columns.   When I did asp work I was able to define a list of column widths (e.g.) width1=80, width2=100 ...) and automatcally calculate the total table width of the Layout *e.g tablewidth = width1 + width2 ...).  This was great because it allowed me to adjust column widths in one spot and automatically adjust the table width.   Of course this was classic asp so the code was on the markup page (aspx), and I could set the width of the <th>  using <th id="th1" runat="server" style='width:"<%=width1 %>";'.  I would like to do the equivalent on aspx pages.  However I can't seem to figure out how to do this.  I tried setting the the widths in the page class (aspx.cs page), but they don't seem to be exposed in the html markup as they were in asp pages.  Did I say I was new to asp.net?  Anyway I was looking for any solution that would allow me to define all the column widths in a single spot (either on aspx or aspx.cs pages) and adjust them easily. 

感谢您的帮助。

推荐答案

这应该有效:

Page.aspx

Page.aspx

    <table id="tbl1" runat="server" border="1">
        <tr>
            <th id="h1">
                Month
            </th>
            <th id="h2">
                Savings
            </th>
        </tr>
    </table>

Page.aspx.cs

Page.aspx.cs

//Dynamically set width
h1.Width = "100px";
h2.Width = "200px";

int totalwidth = 0;
totalwidth = int.Parse(h1.Width.ToString().Replace("px", "")) + int.Parse(h2.Width.ToString().Replace("px", ""));








这篇关于设置&lt; th&gt;的宽度列表视图中的布局模板中的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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