FineUI 官方论坛
标题:
动态添加模板列的问题
[打印本页]
作者:
goldentime
时间:
2015-4-27 10:51
标题:
动态添加模板列的问题
.ASPX代码如下
<body>
<form id="form1" runat="server">
<f:PageManager ID="PageManager1" runat="server">
</f:PageManager>
<f:Grid ID="gdList" runat="server" Title="Grid" >
</f:Grid>
</form>
</body>
复制代码
.ASPX.CS代码如下
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace FineUITest.BaseClass
{
public partial class VouchForm : System.Web.UI.Page
{
WMSService.TaiMeiService_WMSClient WMSClient = new WMSService.TaiMeiService_WMSClient();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FineUIPro.TemplateField tf = new FineUIPro.TemplateField();
tf.Width = Unit.Pixel(120);
tf.HeaderText = "发货单号";
tf.ItemTemplate = new App_Code.UserControls.GenderTemplate();
gdList.Columns.Add(tf);
ListGridView_DataBind();
}
}
private void ListGridView_DataBind()
{
#region 构造结果集结构
DataTable dtResult = new DataTable();
dtResult.Columns.Add("cDPCode");
#endregion
#region 构造结果集内容
string[] rowVals = null;
rowVals = new string[] { "DP150324058" }; dtResult.Rows.Add(rowVals);
rowVals = new string[] { "DP150324057" }; dtResult.Rows.Add(rowVals);
rowVals = new string[] { "DP150324056" }; dtResult.Rows.Add(rowVals);
rowVals = new string[] { "DP150324055" }; dtResult.Rows.Add(rowVals);
rowVals = new string[] { "DP150324054" }; dtResult.Rows.Add(rowVals);
rowVals = new string[] { "DP150324053" }; dtResult.Rows.Add(rowVals);
rowVals = new string[] { "DP150324052" }; dtResult.Rows.Add(rowVals);
rowVals = new string[] { "DP150324051" }; dtResult.Rows.Add(rowVals);
rowVals = new string[] { "DP150324050" }; dtResult.Rows.Add(rowVals);
#endregion
gdList.DataSource = dtResult;
gdList.DataBind();
}
}
}
复制代码
GenderTemplate.cs代码如下
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.IO;
using AspNet = System.Web.UI.WebControls;
namespace FineUITest.App_Code.UserControls
{
public class GenderTemplate : ITemplate
{
public void InstantiateIn(System.Web.UI.Control container)
{
AspNet.Label labGender = new AspNet.Label();
labGender.ID = "cDPCodeItem";
labGender.DataBinding += new EventHandler(labGender_DataBinding);
container.Controls.Add(labGender);
}
private void labGender_DataBinding(object sender, EventArgs e)
{
AspNet.Label labGender = (AspNet.Label)sender;
IDataItemContainer dataItemContainer = (IDataItemContainer)labGender.NamingContainer;
string gender = ((DataRowView)dataItemContainer.DataItem)["cDPCode"].ToString().Trim();
labGender.Text = gender;
}
}
}
复制代码
作者:
goldentime
时间:
2015-4-27 10:52
为什么会变成undefine呢?
作者:
sanshi
时间:
2015-4-27 12:40
先看下常见问题:
http://fineui.com/bbs/forum.php?mod=viewthread&tid=655
作者:
DiabloX
时间:
2015-4-29 15:03
已经根据第六点解决问题
欢迎光临 FineUI 官方论坛 (https://fineui.com/bbs/)
Powered by Discuz! X3.4