ASP.NET DataList控制項

來源:互聯網
上載者:User

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");
       }
   }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.