protected void Page_Load(object sender, EventArgs e) { CreateTable(); using (XHtmlAction xml = new XHtmlAction(true, false)) { xml.Load(Server.MapPath("/demo.html")); //加载html模板。 using (MAction action = new MAction(tableName)) //数据库操作。 { if (action.Fill("1=1")) //查询id=1的数据 { action.Set(1, "hello..."); action.Set(2, DateTime.Now); action.Update(); xml.LoadData(action.Data, "txt"); } MDataTable dt = action.Select(); Response.Write("记录总数:" + dt.Rows.Count); xml.LoadData(dt); xml.SetForeach("divFor", SetType.InnerXml); } Response.Write(xml.OutXml);//输出模板 } }
public static void Bind(object ct, object source, string nodeID) { if (ct == null) { return; } if (ct is XHtmlAction) { #region XHtmlAction 对象处理 XHtmlAction doc = ct as XHtmlAction; MDataTable dt = source as MDataTable; doc.LoadData(dt); XmlNode node = null; if (string.IsNullOrEmpty(nodeID)) { doc.SetForeach(); } else { node = doc.Get(nodeID); if (node != null) { doc.SetForeach(node, node.InnerXml); } } #endregion } else { #region 检测下拉列表控件 if (ct is ListControl) { BindList(ct as ListControl, source as MDataTable); } else if (ct is Win.ListControl) { BindList(ct as Win.ListControl, source as MDataTable); } else { Type t = ct.GetType(); PropertyInfo p = t.GetProperty("DataSource"); if (p != null) { #region DataGridView处理 MethodInfo meth = t.GetMethod("DataBind"); if (meth != null)//web { p.SetValue(ct, source, null); meth.Invoke(ct, null); } else { if (source is MDataTable) { MDataTable dt = source as MDataTable; source = new MDataView(ref dt); } p.SetValue(ct, source, null);//winform } #endregion } else //wpf,sliverlight { p = t.GetProperty("ItemsSource"); if (p != null) { MDataTable dt = null; if (source is MDataTable) { dt = source as MDataTable; source = dt.ToDataTable().DefaultView; } p.SetValue(ct, source, null); //winform p = t.GetProperty("SelectedValuePath"); //判断是不是下拉列表 if (p != null) { p.SetValue(ct, dt.Columns[0].ColumnName, null); p = t.GetProperty("DisplayMemberPath"); p.SetValue(ct, dt.Columns[dt.Columns.Count > 1 ? 1 : 0].ColumnName, null); } } } } #endregion } }