linux社区爱心援助Linux认证系列教程业界动态站务新闻公司招聘网络学院网址大全LPI专题CISCO专题
设为首页
加入收藏
管理团队
JSP  
JAVA  
PERL  
 您的位置:首页 > 开发语言 > asp.net >
栏目导栏
  php
  JSP
  ASP
  asp.net
  JAVA
  c/c++/c#
  perl
  JavaScript
  Basic
  Delphi
资料搜索
热门文章
·NetBPM工作流的一个示例:请假
·Office Web Components(OWC)绘
·asp.net正则表达式语法
·asp.net 2.0 ajax中使用PopupC
·Ado.Net读取Excel常见问题总结
·数据源为空时如何让GridView显
·如何让UpdatePanel支持文件上传
·C#.Net的常见面试试题和参考答
·asp.net ajax客户端编程+jquer
·Brettle.Web.NeatUpload.dll支
·ASP.NET使用Cookie
·ASP.NET DEMO 15: 同时支持行单
·如何使IE的后退按钮无效
·如何在ASP.NET中用OWC绘制图表
·asp.net:正确判断当前用户角色
最新文章
·Ajax Control Toolkit Animati
·讨论一下类似BlogEngine内一次
·使用CSS+SiteMap+UserControl+
·Asp.net中多彩下拉框的实现
·浅谈ASP.NET的Postback
·分清ASP.NET AJAX中的Extender
·Tip:在使用AjaxControlTookit
·有关注册DataItem的一些可能被
·IIRF(Ionic's Isapi Rewrite
·asp.net 客户端回调功能的实现
·关于控件部分的看法--读Progra
·为什么在vista上做开发
·如何封装JS和CSS文件为服务器端
·岂今我看过的最强的排序算法
·设计模式学习笔记之单件模式
Google
 
datagrid技巧之一:代码控制选中行的颜色 览和打印
[ 作者:  加入时间:2007-11-26 16:31:38  来自:Linux联盟收集整理 ]
大家都知道datagrid是一个使用频率很高的控件,在编写ASP.NET代码的时候,我们总希望能让用户选中指定的行以后,让那一行用不同的颜色显示,虽然datagrid样式也有这个功能,但是我们如何编写代码实现呢? gG5Linux联盟
   gG5Linux联盟
  在本例子中,我们首先动态产生1000行,然后当用户选中datagrid中的某一行的时候,那一行就会变为蓝色。代码如下: gG5Linux联盟
   gG5Linux联盟
  using System; gG5Linux联盟
  using System.Collections; gG5Linux联盟
  using System.ComponentModel; gG5Linux联盟
  using System.Data; gG5Linux联盟
  using System.Drawing; gG5Linux联盟
  using System.Web; gG5Linux联盟
  using System.Web.SessionState; gG5Linux联盟
  using System.Web.UI; gG5Linux联盟
  using System.Web.UI.WebControls; gG5Linux联盟
  using System.Web.UI.HtmlControls; gG5Linux联盟
   gG5Linux联盟
  namespace WebApplication_rd gG5Linux联盟
  { gG5Linux联盟
   /// <summary> gG5Linux联盟
   /// Demostrates how to have a datagrid server control be bookmarked gG5Linux联盟
   /// </summary> gG5Linux联盟
   public class datagrid : System.Web.UI.Page gG5Linux联盟
   { gG5Linux联盟
   gG5Linux联盟
   protected System.Web.UI.WebControls.DataGrid DGProducts; gG5Linux联盟
   int bookmarkIndex = 0; // The index of the row that should be scrolled to gG5Linux联盟
   int itemCount = 0; // Counter for the amount of items on the page gG5Linux联盟
   bool bookMark = true; // Controls whether or not the page is bookmarked gG5Linux联盟
   gG5Linux联盟
   #region DGProducts EventHandlers gG5Linux联盟
   gG5Linux联盟
   private void DGProducts_ItemDataBound(object source, DataGridItemEventArgs e) { gG5Linux联盟
   gG5Linux联盟
   if (bookMark) { gG5Linux联盟
   gG5Linux联盟
   LiteralControl anchor = new LiteralControl(); gG5Linux联盟
   anchor.Text = "<a name=\"" + itemCount.ToString() + "\">"; gG5Linux联盟
   itemCount ++; gG5Linux联盟
   e.Item.Cells[0].Controls.Add(anchor); gG5Linux联盟
   gG5Linux联盟
   } gG5Linux联盟
   gG5Linux联盟
   } gG5Linux联盟
   gG5Linux联盟
   private void DGProducts_ItemCommand(object source, DataGridCommandEventArgs e) { gG5Linux联盟
   gG5Linux联盟
   if (e.CommandName == "Select") { gG5Linux联盟
   gG5Linux联盟
   e.Item.BackColor = Color.Blue; gG5Linux联盟
   gG5Linux联盟
   if (bookMark) { gG5Linux联盟
   bookmarkIndex = e.Item.ItemIndex; gG5Linux联盟
   this.InsertScriptBlock(); gG5Linux联盟
   } gG5Linux联盟
   } gG5Linux联盟
   gG5Linux联盟
   } gG5Linux联盟
   gG5Linux联盟
   gG5Linux联盟
   #endregion gG5Linux联盟
   gG5Linux联盟
   #region EventHandlers gG5Linux联盟
   private void Page_Load(object sender, System.EventArgs e) gG5Linux联盟
   { gG5Linux联盟
   gG5Linux联盟
   this.Bind(); gG5Linux联盟
   gG5Linux联盟
   } gG5Linux联盟
   gG5Linux联盟
   #endregion gG5Linux联盟
   gG5Linux联盟
   #region User Defined gG5Linux联盟
   gG5Linux联盟
   private void InsertScriptBlock() { gG5Linux联盟
   gG5Linux联盟
   System.Text.StringBuilder jScript = new System.Text.StringBuilder(); gG5Linux联盟
   jScript.Append("<script language=\"JavaScript\">"); gG5Linux联盟
   jScript.Append("location.href=\"#"); gG5Linux联盟
   jScript.Append(this.bookmarkIndex.ToString()); gG5Linux联盟
   jScript.Append("\";"); gG5Linux联盟
   jScript.Append("</script>"); gG5Linux联盟
   gG5Linux联盟
   this.RegisterClientScriptBlock("Bookmark", jScript.ToString()); gG5Linux联盟
   gG5Linux联盟
   } gG5Linux联盟
   gG5Linux联盟
   gG5Linux联盟
   private void Bind() gG5Linux联盟
   { gG5Linux联盟
   gG5Linux联盟
   DGProducts.DataSource = this.CreateDataSource(1000); gG5Linux联盟
   DGProducts.DataBind(); gG5Linux联盟
   gG5Linux联盟
   } gG5Linux联盟
   gG5Linux联盟
   gG5Linux联盟
   private DataTable CreateDataSource(int count) { gG5Linux联盟
   gG5Linux联盟
   DataTable table = new DataTable(); gG5Linux联盟
   DataColumn column = null; gG5Linux联盟
   DataRow row = null; gG5Linux联盟
   gG5Linux联盟
   // Create 5 columns gG5Linux联盟
   for (int iCol = 0; iCol < 5; iCol++) { gG5Linux联盟
   gG5Linux联盟
   column = new DataColumn("Column: " + iCol.ToString(), typeof(string)); gG5Linux联盟
   table.Columns.Add(column); gG5Linux联盟
   gG5Linux联盟
   } gG5Linux联盟
   gG5Linux联盟
   //Create Rows based on count variable gG5Linux联盟
   for (int iRows = 0; iRows < count; iRows ++) { gG5Linux联盟
   gG5Linux联盟
   row = table.NewRow(); gG5Linux联盟
   gG5Linux联盟
   for (int iCol = 0; iCol < 5; iCol ++) { gG5Linux联盟
   gG5Linux联盟
   row[iCol] = "Value: " + iCol.ToString(); gG5Linux联盟
   gG5Linux联盟
   gG5Linux联盟
   } gG5Linux联盟
   gG5Linux联盟
   table.Rows.Add(row); gG5Linux联盟
   gG5Linux联盟
   } gG5Linux联盟
   gG5Linux联盟
   return table; gG5Linux联盟
   gG5Linux联盟
   } gG5Linux联盟
   gG5Linux联盟
   gG5Linux联盟
   #endregion gG5Linux联盟
   gG5Linux联盟
   #region Web Form Designer generated code gG5Linux联盟
   override protected void OnInit(EventArgs e) gG5Linux联盟
   { gG5Linux联盟
   InitializeComponent(); gG5Linux联盟
   base.OnInit(e); gG5Linux联盟
   } gG5Linux联盟
   gG5Linux联盟
   private void InitializeComponent() gG5Linux联盟
   { gG5Linux联盟
   this.DGProducts.ItemCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.DGProducts_ItemCommand); gG5Linux联盟
   this.DGProducts.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DGProducts_ItemDataBound); gG5Linux联盟
   this.Load += new System.EventHandler(this.Page_Load); gG5Linux联盟
   gG5Linux联盟
   } gG5Linux联盟
   #endregion gG5Linux联盟
   } gG5Linux联盟
   gG5Linux联盟
  }   Linux联盟收集整理 ,转贴请标明原始链接,如有任何疑问欢迎来本站Linux论坛讨论
评论】【加入收藏夹】【 】【打印】【关闭
※ 相关链接
无相关信息