先放上来..有时间整理...
Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
public class UserItemTemplate : ITemplate
{
#region ITemplate 成员
public void InstantiateIn(Control container)
{
Label lbl = new Label();
lbl.DataBinding += new EventHandler(lbl_DataBinding);
container.Controls.Add(lbl);
}
#endregion
private void lbl_DataBinding(object sender, EventArgs e)
{
Label lbl = (Label)sender;
object id=DataBinder.Eval(((GridViewRow)lbl.NamingContainer).DataItem, "id");
lbl.Text = TZZFDD.getUserStr(id);
}
}
public partial class Message_ZFDD : System.Web.UI.Page
{
List<DataControlField> list = new List<DataControlField>();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SetFieldList();
SetGridViewField();
BindGridView();
}
}
private void BindGridView()
{
string checkType = "船舶签证监督检查";
string sqlstr = "select info.*,ship.*,b.berth from TZ_ReddereiusInfo info inner join shipinfo ship on info.v_shipid=ship.shipid inner join tcode_berth b on info.v_berthid=b.id inner join TZ_ReddereiusContent con on info.id=con.v_id where con.v_CheckType='" + checkType + "' and info.v_flag<>'否' and con.v_ischeck='是'";
ClassYagooDbControl.SqlDbControl sql = new ClassYagooDbControl.SqlDbControl();
DataSet ds = sql.ExecuteDataSet(CommandType.Text, sqlstr, null);
GridView1.DataSource =ds;
GridView1.DataBind();
}
private void SetFieldList()
{
switch (1)
{
case 0:
break;
default:
BoundField bf = new BoundField();
TemplateField tf = new TemplateField();
bf = new BoundField();
bf.DataField = "v_ShipNameCn";
bf.HeaderText = "船舶名称";
list.Add(bf);
bf = new BoundField();
bf.DataField = "v_ShipKind";
bf.HeaderText = "船舶种类";
list.Add(bf);
bf = new BoundField();
bf.DataField = "berth";
bf.HeaderText = "泊位";
list.Add(bf);
tf.HeaderText = "执法人员";
tf.ItemTemplate = new UserItemTemplate();
list.Add(tf);
bf = new BoundField();
bf.DataField = "v_LawEnforcementTime";
bf.HeaderText = "执法时间";
list.Add(bf);
break;
}
}
private void SetGridViewField()
{
for(int i = 0 ; i < list.Count;i++)
{
GridView1.Columns.Insert(i, list[i]);
}
}
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
public class UserItemTemplate : ITemplate
{
#region ITemplate 成员
public void InstantiateIn(Control container)
{
Label lbl = new Label();
lbl.DataBinding += new EventHandler(lbl_DataBinding);
container.Controls.Add(lbl);
}
#endregion
private void lbl_DataBinding(object sender, EventArgs e)
{
Label lbl = (Label)sender;
object id=DataBinder.Eval(((GridViewRow)lbl.NamingContainer).DataItem, "id");
lbl.Text = TZZFDD.getUserStr(id);
}
}
public partial class Message_ZFDD : System.Web.UI.Page
{
List<DataControlField> list = new List<DataControlField>();
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
SetFieldList();
SetGridViewField();
BindGridView();
}
}
private void BindGridView()
{
string checkType = "船舶签证监督检查";
string sqlstr = "select info.*,ship.*,b.berth from TZ_ReddereiusInfo info inner join shipinfo ship on info.v_shipid=ship.shipid inner join tcode_berth b on info.v_berthid=b.id inner join TZ_ReddereiusContent con on info.id=con.v_id where con.v_CheckType='" + checkType + "' and info.v_flag<>'否' and con.v_ischeck='是'";
ClassYagooDbControl.SqlDbControl sql = new ClassYagooDbControl.SqlDbControl();
DataSet ds = sql.ExecuteDataSet(CommandType.Text, sqlstr, null);
GridView1.DataSource =ds;
GridView1.DataBind();
}
private void SetFieldList()
{
switch (1)
{
case 0:
break;
default:
BoundField bf = new BoundField();
TemplateField tf = new TemplateField();
bf = new BoundField();
bf.DataField = "v_ShipNameCn";
bf.HeaderText = "船舶名称";
list.Add(bf);
bf = new BoundField();
bf.DataField = "v_ShipKind";
bf.HeaderText = "船舶种类";
list.Add(bf);
bf = new BoundField();
bf.DataField = "berth";
bf.HeaderText = "泊位";
list.Add(bf);
tf.HeaderText = "执法人员";
tf.ItemTemplate = new UserItemTemplate();
list.Add(tf);
bf = new BoundField();
bf.DataField = "v_LawEnforcementTime";
bf.HeaderText = "执法时间";
list.Add(bf);
break;
}
}
private void SetGridViewField()
{
for(int i = 0 ; i < list.Count;i++)
{
GridView1.Columns.Insert(i, list[i]);
}
}
}