回复 3楼dhlalex的帖子
比如当C1Accordion数据绑定,用代码由两种方式添加panes/content到C1Accordion。第一种方法很简单但提供很少的control。第二种要多写代码,但可以把你想的更多的控件使用在AccordionPane.
假设数据源如下:
- // create data
- DataTable dt = new DataTable("People");
- dt.Columns.Add("Name", typeof(string));
- dt.Columns.Add("Notes", typeof(string));
- dt.Columns.Add("Age", typeof(int));
- for (int i = 0; i < 5; i++)
- {
- dt.Rows.Add(string.Format("Name{0}", i), string.Format("Notes{0}", i), i);
- }
复制代码
第一种方法:
- C1Accordion1.HeaderField = "Name";
- C1Accordion1.ContentField = "Notes";
- C1Accordion1.DataSource = dt;
- C1Accordion1.DataBind();
复制代码
第二种方法:
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- C1AccordionPane pane = new C1AccordionPane();
- Literal name = new Literal();
- Literal notes = new Literal();
- Literal age = new Literal();
- Literal _break = new Literal { Text = "<br />" };
- name.Text = dt.Rows[i].Field<string>("Name");
- notes.Text = dt.Rows[i].Field<string>("Notes");
- age.Text = dt.Rows[i].Field<int>("Age").ToString();
- pane.HeaderPanel.Controls.Add(name);
- pane.ContentPanel.Controls.Add(notes);
- pane.ContentPanel.Controls.Add(_break);
- pane.ContentPanel.Controls.Add(age);
- C1Accordion2.Panes.Add(pane);
- }
复制代码 |