<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆 - 30, 文章 - 0, 評論 - 9, 引用 - 0
    數(shù)據(jù)加載中……

    DataGrid使用技巧小總結(jié)-個性化分頁及復(fù)雜表頭

    ? 在使用DataGrid 的時候,總是會有各種各樣的需求,在和數(shù)據(jù)庫打交道的項目中用的最多的恐怕就屬DataGrid 了吧,微軟有時候做的就差那么一點點,所以就需要我們自己來動手實現(xiàn)啦.

    DataGrid 自定義分頁導(dǎo)航

    無需任何其他第三方控件,在DataGrid 自己分頁的基礎(chǔ)上再個性化一點.
    效果:??

    讓DataGrid自己的分頁實現(xiàn)這樣的效果
    [1][2][3][4][5][6]

    ??

    讓DataGrid自己的分頁實現(xiàn)這樣的效果
    [1][2][3][4][5][6]

    ??

    private void grid_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    ??{
    ???if(e.Item.ItemType==ListItemType.Pager)
    ???{????
    ????foreach (Control c in e.Item.Cells[0].Controls)
    ????{
    ?????if (c is Label)? //
    當(dāng)前頁數(shù)
    ?????{
    ??????? Label lblpage=(Label)c;
    //??????lblpage.ForeColor= System.Drawing.ColorTranslator.FromHtml("#e78a29");?//#e78a29 ,#FF0000?????
    //??????lblpage.Font.Bold=true;
    ??????? lblpage.Text="[<font color=#e78a29><b>"+lblpage.Text+"</b></font>]";?????
    ??????//((Label)c).ForeColor = System.Drawing.Color.Green;??????
    //??????break;
    ?????}
    ?????if(c is LinkButton) //
    鏈接的其他頁數(shù)
    ?????{??????
    ???????? LinkButton linkButton = (LinkButton)c; ??????
    ???????? linkButton.Text = "[" + linkButton.Text+"]";
    ?????}
    ????}????
    ???}
    ??}

    ?

    ?

    DataGrid等控件中的自動編號:

    添加一個模版列:

    <asp:TemplateColumn?HeaderText="No.">
    ????
    <ItemStyle?HorizontalAlign="Center"></ItemStyle>
    ????
    <ItemTemplate>
    ????????
    <asp:Label?runat="server"?Text='<%#?dgCustomize.CurrentPageIndex*dgCustomize.PageSize+dgCustomize.Items.Count+1?%>'>
    ????????
    </asp:Label>
    ????
    </ItemTemplate>
    </asp:TemplateColumn>

    ?

    ?

    DataGrid中創(chuàng)建復(fù)雜表頭

    方法一:用table實現(xiàn)

    ??<form id="Form1" method="post" runat="server">
    ???<TABLE id="Table1" runat="server" cellSpacing="1" cellPadding="2" width="580" border="1"
    ????bgcolor="#cc6633" bordercolor="#cc9966" style="FONT-SIZE:9pt;BORDER-BOTTOM:0px">
    ????<TR align="center">
    ?????<TD colspan="2" width="380" style="HEIGHT: 21px"></TD>
    ?????<TD width="200" colspan="2" style="HEIGHT: 21px"></TD>
    ????</TR>
    ????<TR align="center">
    ?????<TD width="200" bgcolor="#66cc99"><FONT face="
    宋體"></FONT></TD>
    ?????<TD width="180" bgcolor="white"><FONT face="
    宋體"></FONT></TD>
    ?????<TD width="160" bgcolor="#99cccc"></TD>
    ?????<TD width="40" bgcolor="#009999"></TD>
    ????</TR>
    ???</TABLE>
    ???<asp:DataGrid id="DataGrid1" width="580px" AlternatingItemStyle-BackColor="#6699ff" CellPadding="2"
    ????CellSpacing="1" BorderWidth="1" BorderColor="#cc9966" Font-Size="9pt" runat="server" ShowHeader="False"
    ????AutoGenerateColumns="False">
    ????<Columns>
    ?????<asp:BoundColumn DataField="Title">
    ??????<ItemStyle Width="200px"></ItemStyle>
    ?????</asp:BoundColumn>
    ?????<asp:BoundColumn DataField="CreateDate">
    ??????<ItemStyle Width="180px"></ItemStyle>
    ?????</asp:BoundColumn>
    ?????<asp:BoundColumn DataField="pid">
    ??????<ItemStyle Width="160px"></ItemStyle>
    ?????</asp:BoundColumn>
    ?????<asp:BoundColumn DataField="HitCount">
    ??????<ItemStyle Width="40px"></ItemStyle>
    ?????</asp:BoundColumn>
    ????</Columns>
    ???</asp:DataGrid>???
    ??</form>?

    窗體頂端

    ?

    ?

    ?

    ?

    ?

    ?

    窗體底端

    方法二:動態(tài)生成表頭

    生成雙層表頭:
    ??private void grid_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    ??{

    ???if (e.Item.ItemType == ListItemType.Header)
    ???{
    //????e.Item.Cells[0].ColumnSpan = 1;//
    這是第一列的跨列數(shù)
    ????StringBuilder strtext=new StringBuilder();
    ????strtext.Append("\\</td>");
    ????strtext.Append("<td colspan=4>
    生活照明</td>");
    ????strtext.Append("<td colspan=2>
    一般照明</td>");
    ????strtext.Append("<td colspan=2>
    工付業(yè)</td>");
    ????strtext.Append("<td colspan=2>
    農(nóng)業(yè)</td>");
    ????strtext.Append("<td colspan=2>
    合計</td>");
    ????strtext.Append("</tr>");
    ????strtext.Append("<tr>");
    ????strtext.Append("<td>" + e.Item.Cells[0].Text);???????????????
    ????e.Item.Cells[0].Text =strtext.ToString();

    ???}

    }

    整個表頭內(nèi)容:<tr><td>??e.Item.Cells[0].Text =的內(nèi)容? </td></tr>

    加起來就是表頭的樣式。

    生活照明

    一般照明

    工付業(yè)

    農(nóng)業(yè)

    合計

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    生成三層表頭:

    if (e.Item.ItemType == ListItemType.Header)
    ???{????
    ????StringBuilder strtext=new StringBuilder();
    ????strtext.Append("</td>");
    ????strtext.Append("<td colspan= 6>
    當(dāng)月</td>");
    ????strtext.Append("</tr>");

    ????strtext.Append("<tr>");?
    ????strtext.Append("<td colspan=2>
    居民</td>");
    ????strtext.Append("<td colspan=2>
    一般</td>");
    ????strtext.Append("<td colspan=2>
    工付業(yè)</td>");
    ????strtext.Append("</tr>");

    ????strtext.Append("<tr>");
    ????strtext.Append("<td>" + e.Item.Cells[0].Text);???????????????
    ????e.Item.Cells[0].Text =strtext.ToString();
    ???}

    當(dāng)月

    居民

    一般

    工付業(yè)

    ?

    ?

    ?

    ?

    ?

    ?

    posted on 2006-11-10 14:31 風(fēng)雨兼程 閱讀(276) 評論(0)  編輯  收藏 所屬分類: Asp.net

    主站蜘蛛池模板: 国产成人亚洲综合a∨| 无码专区AAAAAA免费视频| 亚洲伊人色欲综合网| 日韩视频在线观看免费| 亚洲资源最新版在线观看| 免费大香伊蕉在人线国产| 国产一级片免费看| 亚洲妇女无套内射精| 亚洲女初尝黑人巨高清| 成在人线AV无码免费| 两性色午夜视频免费网| 亚洲熟女综合色一区二区三区| 国产精品V亚洲精品V日韩精品| 波多野结衣中文字幕免费视频 | 午夜视频免费成人| 中国一级特黄的片子免费 | 亚洲美免无码中文字幕在线| 国产精品无码免费视频二三区| 免费在线看污视频| 香港经典a毛片免费观看看| 亚洲精品午夜在线观看| 中文字幕亚洲激情| 最好免费观看韩国+日本| 99精品视频在线免费观看| 污视频网站免费在线观看| 亚洲av日韩av无码av| 久久久久久a亚洲欧洲aⅴ| 免费无码一区二区三区蜜桃大 | 亚洲码国产精品高潮在线| 免费看香港一级毛片| 免费看h片的网站| 日本一区午夜艳熟免费| 国产精品久久久久久亚洲小说| 亚洲香蕉在线观看| 亚洲综合久久1区2区3区| 亚洲中文字幕无码不卡电影| 国产免费观看视频| 女人张开腿给人桶免费视频| 国产精品免费观看| 久久99国产乱子伦精品免费| 日韩av无码免费播放|