Repeater和TreeView

 

Repeater 控件是模板化的数据绑定列表,Repeater 控件是“无外观的”,即:它不具有任何内置布局或样式,也就不会产生任何数据控制表格来控制数据的显示。因此,我们必须在控件的模板中明确声明所有 HTML 布局标记、格式标记和样式标记。
分页:
  protected void Button6_Click(object sender, EventArgs e)
    {
        this.BindProduct("1");
    }
    protected void Button9_Click(object sender, EventArgs e)
    {
        int count = Convert.ToInt32(this.HiddenField2.Value);
        this.BindProduct(count.ToString());
    }
    protected void Button7_Click(object sender, EventArgs e)
    {
        int index = Convert.ToInt32(this.HiddenField1.Value);
        if (index > 0)
            index--;
        this.BindProduct(index.ToString());
    }
    protected void Button8_Click(object sender, EventArgs e)
    {
        int index = Convert.ToInt32(this.HiddenField1.Value);
        int count = Convert.ToInt32(this.HiddenField2.Value);
       
        if (index < count)
            index++;
        this.BindProduct(index.ToString());
    }
  private void BindProduct(string pageindex)
    {
        string str = ConfigurationManager.ConnectionStrings["studentCnn"].ConnectionString;
        using (SqlConnection sqlCnn = new SqlConnection(str))
        {
            SqlDataAdapter da = new SqlDataAdapter("sp_Student_Select_by_Page_rowNumber", sqlCnn);
            da.SelectCommand.Parameters.AddWithValue("@pageIndex", pageindex);
            da.SelectCommand.Parameters.Add("@pageCount", SqlDbType.Int).Direction = ParameterDirection.Output;
            da.SelectCommand.Parameters.AddWithValue("@pageSize", 2);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;
            DataSet ds = new DataSet();
            da.Fill(ds);
            this.DataList1.DataSource = ds.Tables[0].DefaultView;
            this.DataList1.DataBind();
            this.HiddenField1.Value = pageindex;
            this.HiddenField2.Value = da.SelectCommand.Parameters["@pageCount"].Value.ToString();

        }
    }


Treeview数据的动态绑定:
   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindTree();
        }
    }
    private void BindTree()
    {
        DataTable dt = GetData();
        this.FillNode(dt,null);
    }
    private void FillNode(DataTable dt,TreeNode no)
    {
        DataView dv = new DataView(dt);
        if (no == null)
        {
            dv.RowFilter = "parentid='0'";

        }
        else
        {
            dv.RowFilter = "parentid='" + no.Value + "'";
        }
        foreach (DataRowView item in dv)
        {
            TreeNode node = new TreeNode(item["menuname"].ToString(), item["menuid"].ToString());
            FillNode(dt, node);
            if (no == null)
            {
                this.TreeView1.Nodes.Add(node);
            }
            else
            {
                no.ChildNodes.Add(node);
            }
        }
    }
    private DataTable GetData()
    {
        string str = ConfigurationManager.ConnectionStrings["sqlstr"].ConnectionString;
        using (SqlConnection cnn=new SqlConnection(str))
        {
            SqlCommand cmm = cnn.CreateCommand();
            cmm.CommandText = "select * from MenuTree order by ParentID,MenuOrder";
            SqlDataAdapter da = new SqlDataAdapter(cmm);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds.Tables[0];
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值