using System; using System.Collections.Generic; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Text; using System.IO; using AspNet = System.Web.UI.WebControls; namespace FineUI.Examples.grid { public partial class grid_edit_checkboxlist : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGrid(); } } #region BindGrid private void BindGrid() { DataTable table = DataSourceUtil.GetDataTable(); Grid1.DataSource = table; Grid1.DataBind(); } #endregion #region Events protected void Grid1_RowDataBound(object sender, GridRowEventArgs e) { AspNet.CheckBoxList cblHobby = (AspNet.CheckBoxList)Grid1.Rows[e.RowIndex].FindControl("cblHobby"); DataRowView row = e.DataItem as DataRowView; string hobby = row["Hobby"].ToString() + ","; foreach (AspNet.ListItem item in cblHobby.Items) { if (hobby.Contains(item.Value + ",")) { item.Selected = true; } else { item.Selected = false; } } } protected void Button1_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); sb.Append("
编号 | 姓名 | 用户输入的爱好 |
---|---|---|
{0} | ", rowDataKeys[0]); sb.AppendFormat("{0} | ", rowDataKeys[1]); GridRow row = Grid1.Rows[i]; AspNet.CheckBoxList cblHobby = (AspNet.CheckBoxList)row.FindControl("cblHobby"); sb.AppendFormat("{0} | ", GetHobbies(cblHobby)); sb.Append("