下载中心┊文章中心┊软件分类┊更新软件┊推荐下载┊热门软件┊更新文章┊热门文章
 
《拓文asp.net网站内容管理系统》官方演示站。
 设为首页    
 收藏本站
 作者:黄振安
 
网站首页 开源拓文 .NET编程 网站编程 网页设计 图形图像 数据库 软件工程留言本
    站内搜索:   
您现在的位置: 拓文网络 → 文章中心 → .NET编程 → ASP.NET → asp.net 2.0下一个标准GRIDVIEW功能的实现(不用datasource控件)2[正文]

热 门 文 章

相 关 文 章
  • 使用 Visual Basic 或 Visual ...
  • asp.net 2.0下一个标准GRIDVIE...
  • asp.net 2.0下一个标准GRIDVIE...
  • ASP.NET 2.0页面框架简要慨述(2)
  • ASP.NET 2.0页面框架简要慨述(1)
  • ASP.NET 2.0中的Web和HTML服务...
  • ASP.NET 2.0中的Web和HTML服务...
  • ASP.NET 2.0中的Web和HTML服务...
  • ASP.NET 2.0中的Web和HTML服务...
  • ASP.NET 2.0 中 Web 事件(3)
  • asp.net 2.0下一个标准GRIDVIEW功能的实现(不用datasource控件)2
     
    [作者:不详    转贴自:    点击数:    字体:【大 中 小】    更新时间:2006-10-2 16:18:45]

         }
       为了实现每列都可以自动点击排序,可以设置allowsorting=true,然后设置OnSorting="GridView1_Sorting",其中gridview_sorting
      代码为
       protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
       {
       ViewState["sortexpression"] = e.SortExpression;
      
       if (ViewState["sortdirection"] == null)
       {
       ViewState["sortdirection"] = "asc";
       }
       else
       {
       if (ViewState["sortdirection"].ToString() == "asc")
       {
       ViewState["sortdirection"] = "desc";
       }
       else
       {
       ViewState["sortdirection"] = "asc";
       }
       }
       BindGrid();
       }
      很明显,设置viewsate来保存每次排序时的顺序,上面的相信很容易理解。
       最后,实现编辑功能,因为在ASPx页面中已经设置了OnRowEditing="GridView1_RowEditing",其中GridView1_RowEditing的代码为
       protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
       {
       int empid;
       string fname, lname;
       empid = int.Parse(GridView1.Rows[e.RowIndex].Cells[0].Text);
       fname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
       lname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
      
       SqlConnection cnn = new SqlConnection(@"data source=localhost;initial catalog=northwind;user id=sa;password=123456");
       cnn.Open();
       SqlCommand cmd = new SqlCommand("update employees set firstname=@fname,lastname=@lname where employeeid=@empid", cnn);
       cmd.Parameters.Add(new SqlParameter("@fname",fname));
       cmd.Parameters.Add(new SqlParameter("@lname", lname));
       cmd.Parameters.Add(new SqlParameter("@empid", empid));
       cmd.ExecuteNonQuery();
      
      
      
        做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。


    页次:1/1  1篇/页  首页   上一页   下一页   尾页  合计 1 篇 Go:
     
    上一篇:asp.net 2.0下一个标准GRIDVIE...
    下一篇:asp.net 2.0下一个标准GRIDVIE...
    winner 打印本页 关闭窗口

         文 章 评 论
    评论人 查看该文章的评论 发表时间
       笔 名* : 0 50分 60分 70分 80分 90分 100分
    评论内容 *: (最多600字。当前字数:0)


    没有相关评论,欢迎您参与!

    - 关于本站 - 网站帮助 - 下载声明 - 友情连接 - 网站地图 -
    Copyright © 2005-2006 rtht.Com. All Rights Reserved . [桂ICP备06004496号]程序设计: 拓文ASP.NET网站内容管理系统 V2.6 SQL版