GridView 自动生成列 没有整理.

 

先放上来..有时间整理...

ContractedBlock.gif ExpandedBlockStart.gif 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]);
        }
    }
}

转载于:https://www.cnblogs.com/jgjgjg23/archive/2009/06/12/1501951.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值