ASP.NET DataList控件

DataList控件
实现查看详细信息按钮
1.     在普通项模板中添加一个按钮 将该按钮的 commandName 属性设置为”select”
2.     在DataList的ItemCommand 事件中 实现选择行

代码
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
     {
        
if (e.CommandName=="select")
         {
            
this.DataList1.SelectedIndex = e.Item.ItemIndex;
            
this.DataList1.DataBind();
         }
}

3.     在选中项 模板中 显示需要显示的信息
       <SelectedItemTemplate>
         <%# DataBinder.Eval(Container.DataItem,"title") %>
         发行日期:<%# DataBinder.Eval(Container.DataItem,"publishDate","{0:d}") %>
         <%# DataBinder.Eval(Container.DataItem,"contentdescription") %>
         </SelectedItemTemplate>
GirdView控件

添加字段页面:

HyperLinkField 超链接项
主要属性:

DataNavigateUrlFields         将要绑定的数据源字段名称
DataNavigateUrlFormatString   将以get方式提交到目标页面如:BookDetail.aspx?id={0}
连接后面的?id= 是提交地址 {0} 是占位符
或者:
比如将要提交的页面是一个有序的页面它根据表中的ID字段来命名页面名称
DataNavigateUrlFields       属性为 BookName
DataNavigateUrlFormatString 属性为 Books/{0}.aspx

RowDataBound事件 实现鼠标悬停当前行变色

代码
  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
   {
      
if (e.Row.RowType == DataControlRowType.DataRow)//如果当前行的类型为数据行
       {
          
//将当前绑定的行添加一个属性
          
//当鼠标悬停 设置背景为蓝色           e.Row.Attributes.Add("onmouseover","currentcolor=this.style.backgroundColor;this.style.backgroundColor='#6699ff'");         
          
//当鼠标离开 恢复背景颜色
           e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
       }
   }
posted @ 2010-09-28 17:09  BuildNewApp  阅读(308)  评论(0编辑  收藏  举报