http://www.4guysfromrolla.com/webtech/050801-1.shtml

解决方案 »

  1.   

    ItemDataBound Event:
    public void ItemDataBound(Object sender, DataGridItemEventArgs e)
    {
    int intCellCount=e.Item.Cells.Count;
    DataRowView drv = (DataRowView) e.Item.DataItem;
    if (drv == null) return;
    //数据类型
    if (drv["数据类型"]!=null)
    {
    TableCell tc = e.Item.Cells[7];
    tc.Attributes["Width"]="50px";
    string _sql="SELECT DISTINCT a.coldatatype "+
    "FROM sys_FlexHeadCtl as a "+
    "WHERE (((a.coldatatype)<>'')) "+
    "ORDER BY a.coldatatype";
    if(oleCn.State!=ConnectionState.Open)
    {
    oleCn.ConnectionString=strSqlCon;
    oleCn.Open();
    }
    DataSet ds = new DataSet();
    OleDbDataAdapter oleDa=new OleDbDataAdapter();
    oleCmd.Connection=oleCn;
    oleCmd.CommandText=_sql;
    oleCmd.CommandType=CommandType.Text;
    oleDa.SelectCommand=oleCmd;
    oleDa.Fill(ds,"myDDL");
    DropDownList ddl=new DropDownList();
    ddl.BorderStyle=BorderStyle.None;
    ddl.DataTextField="coldatatype";
    //ddl.DataValueField="coldatatype"; 
    ddl.Style.Add("BACKGROUND-COLOR","transparent");
    ddl.DataSource=ds.Tables[0];
    ddl.DataBind();
    tc.Controls.Add(ddl);
    ListItem li=new ListItem("","");
    ddl.Items.Insert(0,li);
    if((drv["数据类型"]).ToString()!="")
    ddl.SelectedIndex=ddl.Items.IndexOf(ddl.Items.FindByText((drv["数据类型"]).ToString()));
    else
    ddl.SelectedIndex=0;
    }
    ........
      

  2.   

    <asp:DataGrid id="DataGrid1"   runat="server">
    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid>