Username: Password:

怎样让DataGrid自动生成序号-ASP教程,数据库相关
来源:作者: 发布时间:2007-12-25 13:37:29

在datagrid的第一列自动生成序号,如下图:

    代码实现:

前台(webform1.aspx):

<%#getcount()%>

   

后台(webform1.aspx.cs):

int count;

private void page_load(object sender, system.eventargs e)

{

     if(!ispostback)

     {

sqlconnection cnn = new sqlconnection();

cnn.connectionstring = "data source=localhost;initial catalog=northwind;password=;"

         +"persist security info=true;user id=sa;workstation id=apj062;packet size=4096";

          string sqlstr = "select top 10 customerid, companyname, city, address from customers";

         cnn.open();

         sqldataadapter ad = new sqldataadapter(sqlstr,cnn);

         datatable dt = new datatable();

         ad.fill(dt);

grdcustomer.datasource = dt;

         grdcustomer.databind();

     }

//自动记数函数,在前台调用

public int getcount()

{

     return ++count ;

}

喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅