css设定表格宽度

80酷酷网    80kuku.com

  css靠!
你真的不会CSS?那你先找一下CSS的资料吧。
比如你的CSS文件里面有以下内容:
Class1{width:20%;}
Class2{width:30%;}

然后写你的DataGrid,你不要使用它默认的写法,将AutoGenrated(这个单词我忘了怎么拼了)设置为false,然后自己绑定到DataGrid里面的模板里面,在每一项里面设置,老天,我刚才又看了一下你的贴子,这才明白,你只是使用的DataGrid的原始功能呀?
看看下面的写法:
<asp:DataGrid id="programmaticID" runat=server
   DataSource='<%# DataBindingExpression %>'
   AutoGenerateColumns="False"
   (other properties)>

   <Columns>
      <asp:BoundColumn
         DataField="DataSourceField"
         DataFormatString="FormatString"
         FooterText="FooterText"
         HeaderImageUrl="url"
         HeaderText="HeaderText"
         ReadOnly="True|False"
         SortField="DataSourceFieldToSortBy"
         Visible="True|False"
         FooterStyle-property="value"
         HeaderStyle-property="value"
         ItemStyle-property="value"
      />

      <asp:ButtonColumn
         ButtonType="LinkButton|PushButton"
         Command="BubbleText"
         DataTextField="DataSourceField"
         DataTextFormatString="FormatString"
         FooterText="FooterText"
         HeaderImageUrl="url"
         HeaderText="HeaderText"
         ReadOnly="True|False"
         SortField="DataSourceFieldToSortBy"
         Text="ButtonCaption"
         Visible="True|False"
      />

      <asp:EditCommandColumn
         ButtonType="LinkButton|PushButton"
         CancelText="CancelButtonCaption"
         EditText="EditButtonCaption"
         FooterText="FooterText"
         HeaderImageUrl="url"
         HeaderText="HeaderText"
         ReadOnly="True|False"
         SortField="DataSourceFieldToSortBy"
         UpdateText="UpdateButtonCaption"
         Visible="True|False"
        />

      <asp:HyperLinkColumn
         DataNavigateUrlField="DataSourceField"
         DataNavigateUrlFormatString="FormatExpression"
         DataTextField="DataSourceField"
         DataTextFormatString="FormatExpression"
         FooterText="FooterText"
         HeaderImageUrl="url"
         HeaderText="HeaderText"
         NavigateUrl="url"
         ReadOnly="True|False"
         SortField="DataSourceFieldToSortBy"
         Target="window"
         Text="HyperLinkText"
         Visible="True|False"
       />

      <asp:TemplateColumn>
         FooterText="FooterText"
         HeaderImageUrl="url"
         HeaderText="HeaderText"
         ReadOnly="True|False"
         SortField="DataSourceFieldToSortBy"
         Visible="True|False"
         <HeaderTemplate>
             Header template HTML
         </HeaderTemplate >
         <ItemTemplate>
             ItemTemplate HTML
         </ItemTemplate>
         <EditItemTemplate>
             EditItem template HTML
         </EditItemTemplate>
         <FooterTemplate>
             Footer template HTML
         </FooterTemplate>
      </asp:TemplateColumn>
    </Columns>
</asp:DataGrid>
然后你可以为每一个模板指定一个CSSClass了,或者直接在里面设置,就不必再使用CSS了。 

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: