牙签学技术

一根牙签的业余爱好
  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理

[ASP.NET]排序和分布代码-DataGrid

Posted on 2008-07-25 14:12 『一根牙签』 阅读(12) 评论(0)  编辑 收藏 所属分类: ASP.NET
dim myconn as oledbConnection

dim mycomm as oledbDataAdapter

dim ds as new dataset

dim connstr as string

dim sqlstr as string

dim sortField as string

        

sub page_load(a as object,e as eventargs)

connstr
=ConfigurationSettings.AppSettings("Connstr")

myconn
=new oledbconnection(connstr)

    
if not (ispostback)

        
if sortField="" then

            sortField
="Tjobs"

        
end if

        bind

    
end if

end sub




sub Bind()        

    sqlstr
="select * from Teacher"            

    mycomm
=new oledbdataadapter(sqlstr,myconn)

    mycomm.fill(ds,
"Teacher")

    
dim dv2 as dataview

        dv2
=ds.tables("Teacher").defaultview

        dv2.sort
=sortfield

        grid1.datasource
=dv2

        grid1.databind()        

end sub




sub mygriddata_page(s as object,e as datagridPageChangedEventargs)

    grid1.currentpageindex
=e.newpageindex

    bind

end sub




sub mygriddata_Sort(s as object,e as datagridSortCommandEventargs)

    sortField
=e.sortExpression

    bind

end sub










<asp:datagrid id="grid1" runat="server" 

    Autogeneratecolumns
="false" backcolor="white"

    boarderwidth
="1px" borderstyle="solid" bordercolor="tan" cellpadding="2" cellspacing="0" 

    font
-name="verdana" font-size="8pt" allowpaging="true" pagesize="5" 

    pagerstyle
-mode="numericPages" Pagestyle-nextpagetext="Next"

    Pagestyle
-PrevpageText="Prev" PageStyle-Horizontalalign="right"

    onPageIndexChanged
="myGriddata_page" allowsorting="true" onsortCommand="mygriddata_Sort">

        

    
<columns>

        
<asp:boundcolumn headertext="Tjobs" datafield="Tjobs" sortExpression="Tjobs">

            
<headerstyle width="150px"></headerstyle>

        
</asp:boundcolumn>



        
<asp:boundcolumn headertext="Tname" datafield="Tname" sortExpression="Tname">

            
<headerstyle width="150px"></headerstyle>

        
</asp:boundcolumn>



        
<asp:boundcolumn headertext="Tpic" datafield="Tpic" sortExpression="Tpic">

            
<headerstyle width="150px"></headerstyle>

        
</asp:boundcolumn>



        
<asp:boundcolumn headertext="TProfiles" datafield="TProfiles" >

            
<headerstyle width="150px"></headerstyle>

        
</asp:boundcolumn>

            

        
<asp:boundcolumn headertext="TExpectations" datafield="TExpectations" >

            
<headerstyle width="150px"></headerstyle>

        
</asp:boundcolumn>



        
<asp:templatecolumn >                             

            
<itemtemplate> 

                
<a id="anchor1" runat="server" href='<%# Container.dataitem("Tpic") %>'>查看</a>

            
</itemtemplate>                                                     

        
</asp:templatecolumn> 

    
</columns>

    
<headerStyle backcolor="darkred" forecolor="white" font-bold="true"></headerstyle>

    
<itemstyle forecolor="darkslateblue" ></itemstyle>

    
<alternatingitemstyle backcolor="beige" />

</asp:datagrid>
技术改变生活,生活改变思想,思想改变技术。
Tag标签: ASP.NET,DataGrid