OnRowDataBound="GridView1_RowDataBound"
              <asp:TemplateField HeaderText="员工性别">
                <ItemTemplate>
                   <asp:DropDownList ID="DDsex" runat="server" DataSource='<%# sexbind()%>' DataValueField="sex" DataTextField="sex">
                   </asp:DropDownList>
                </ItemTemplate>
              </asp:TemplateField>
public OleDbDataReader sexbind()
    {
        string sql = "select distinct sex from [user]";
        OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("test.mdb"));
        OleDbCommand cmd = new OleDbCommand(sql, conn);
        conn.Open();
        return cmd.ExecuteReader();
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex >= 0)
        {
            string sex = e.Row.Cells[4].Text;
            DropDownList ddsex = (DropDownList)e.Row.Cells[3].FindControl("DDsex");
            ddsex.Text = sex;
            
        }
        if ((e.Row.RowType == DataControlRowType.DataRow) || (e.Row.RowType == DataControlRowType.Header) || (e.Row.RowType == DataControlRowType.Footer))
        {
            e.Row.Cells[4].Visible = false;
        }
    }
演示 下载