給datagrid的按鈕列添加css

來源:互聯網
上載者:User

今天改介面,發現datagrid可以用cssclass設定css風格,但是按鈕列沒有cssclass屬性。忙活了半天,發現只能用程式設定按鈕列屬性。
設定方法如下(C#版本)
為datagrid添加ItemCreat事件,在ItemCreat事件裡面添加如下代碼

private void dgBoxList_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        {
            if(e.Item.ItemType== ListItemType.Item  ||    e.Item.ItemType == ListItemType.AlternatingItem ) 
            {
                Button    myButton=(Button)e.Item.Cells[2].Controls[0];
                //Cells[i].Controls[j] i為你的按鈕列在datagrid的第幾行,從0開始的,
                //比如你的按鈕列是第三行,則i為2,Controls[j],j為該列的第幾個控制項,預設一般是0。
                  myButton.CssClass = "button" ;//這裡設定你為該按鈕準備好的css
            
            }
        
        

        }
        
相關文章

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.