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

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

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

    網站開發

    asp.net
    隨筆 - 30, 文章 - 0, 評論 - 9, 引用 - 0
    數據加載中……

    DataGrid使用技巧小總結-個性化分頁及復雜表頭

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

    DataGrid 自定義分頁導航

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

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

    ??

    讓DataGrid自己的分頁實現這樣的效果
    [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)? //
    當前頁數
    ?????{
    ??????? 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) //
    鏈接的其他頁數
    ?????{??????
    ???????? 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中創建復雜表頭

    方法一:用table實現

    ??<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>?

    窗體頂端

    ?

    ?

    ?

    ?

    ?

    ?

    窗體底端

    方法二:動態生成表頭

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

    ???if (e.Item.ItemType == ListItemType.Header)
    ???{
    //????e.Item.Cells[0].ColumnSpan = 1;//
    這是第一列的跨列數
    ????StringBuilder strtext=new StringBuilder();
    ????strtext.Append("\\</td>");
    ????strtext.Append("<td colspan=4>
    生活照明</td>");
    ????strtext.Append("<td colspan=2>
    一般照明</td>");
    ????strtext.Append("<td colspan=2>
    工付業</td>");
    ????strtext.Append("<td colspan=2>
    農業</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();

    ???}

    }

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

    加起來就是表頭的樣式。

    生活照明

    一般照明

    工付業

    農業

    合計

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    ?

    生成三層表頭:

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

    ????strtext.Append("<tr>");?
    ????strtext.Append("<td colspan=2>
    居民</td>");
    ????strtext.Append("<td colspan=2>
    一般</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();
    ???}

    當月

    居民

    一般

    工付業

    ?

    ?

    ?

    ?

    ?

    ?

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

    主站蜘蛛池模板: 免费中文字幕在线观看| 一区二区免费视频| 日韩毛片无码永久免费看| 亚洲国产午夜精品理论片| 8090在线观看免费观看| 亚洲嫩草影院在线观看| 一二三四在线观看免费高清中文在线观看 | 亚洲国产精品白丝在线观看| 久久永久免费人妻精品下载| 久久亚洲春色中文字幕久久久| 美女视频黄a视频全免费网站色窝| 亚洲av无码不卡| 免费A级毛片无码A∨免费| 亚洲天堂2016| 国产一级淫片a免费播放口之| 成人久久久观看免费毛片| 综合亚洲伊人午夜网 | 亚洲成熟丰满熟妇高潮XXXXX| heyzo亚洲精品日韩| 三年在线观看免费观看完整版中文| 亚洲国产成人精品无码区在线观看 | 中文字幕无码一区二区免费| 亚洲综合久久综合激情久久| 成人免费一级毛片在线播放视频| 亚洲精品无码久久久久牙蜜区| 亚洲精品无码AV中文字幕电影网站| 国产午夜精品免费一区二区三区| 亚洲自偷精品视频自拍| 日韩a级毛片免费观看| 中文字幕免费在线播放| 亚洲人成在线免费观看| 免费人成网站在线高清| 亚洲精品免费视频| 亚洲av综合av一区二区三区| 亚洲中文字幕无码久久精品1| 成人在线免费看片| 免费毛片毛片网址| 亚洲大香人伊一本线| 亚洲精品国产电影| 永久在线免费观看| 中美日韩在线网免费毛片视频|