数据绑定控件Repeater的使用

 cs代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using 数据绑定.DAL.DataSet1TableAdapters;
using System.Data;
using System.Web.UI.HtmlControls;

namespace 数据绑定
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            T_UserTableAdapter adapter = new T_UserTableAdapter();
            if (e.CommandName == "Enabled")
            {
                adapter.UpdateEnabled(Convert.ToInt32(e.CommandArgument));
                Repeater1.DataBind();
            }
            else
            {
                adapter.UpdateDisabled(Convert.ToInt32(e.CommandArgument));
                Repeater1.DataBind();
            }
        }

        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {

            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {

                DataRowView viewRow = (DataRowView)e.Item.DataItem;
                var row = (数据绑定.DAL.DataSet1.T_UserRow)viewRow.Row;
                if (row.State == "启用")
                {
                    Button btnQ = (Button)e.Item.FindControl("btnEnabled");
                    btnQ.Visible = false;
                }
                else if (row.State == "禁用")
                {

                    HtmlTableRow rColor = (HtmlTableRow)e.Item.FindControl("hrColor");
                    rColor.Attributes["class"] = "ni";

                    Button btnJ = (Button)e.Item.FindControl("btnDisabled");
                    btnJ.Visible = false;
                }
                else
                {
                    throw new Exception("非法的State状态!");
                }
            }
        }


    }
}
  

  

 

aspx代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="数据绑定._Default" %>





    
    



    
用户名状态操作
<%#Eval("UserName") %><%#Eval("State") %>



 

转载于:https://www.cnblogs.com/blackHorseplan/p/3887465.html

你可能感兴趣的:(ui,xhtml,c#)